Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3584c0b

Browse files
committed
CPP: Speed up InitializationFunctions.qll's getTarget.
1 parent 2d64fed commit 3584c0b

1 file changed

Lines changed: 30 additions & 21 deletions

File tree

cpp/ql/src/Security/CWE/CWE-457/InitializationFunctions.qll

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -618,34 +618,43 @@ Function getAPossibleDefinition(Function undefinedFunction) {
618618
) and
619619
result.isDefined()
620620
}
621+
622+
private Function getTarget1(Call c) {
623+
/*
624+
* If there is at least one defined target after performing some simple virtual dispatch
625+
* resolution, then the result is all the defined targets.
626+
*/
627+
628+
result = VirtualDispatch::getAViableTarget(c) and
629+
result.isDefined()
630+
}
631+
632+
private Function getTarget2(Call c) {
633+
/*
634+
* If we can use the heuristic matching of functions to find definitions for some of the viable
635+
* targets, return those.
636+
*/
637+
638+
not exists(getTarget1(c)) and
639+
result = getAPossibleDefinition(VirtualDispatch::getAViableTarget(c))
640+
}
641+
642+
private Function getTarget3(Call c) {
643+
not exists(getTarget1(c)) and
644+
not exists(getTarget2(c)) and
645+
// Otherwise, the result is the undefined `Function` instances.
646+
result = VirtualDispatch::getAViableTarget(c)
647+
}
621648

622649
/**
623650
* Gets a possible target for the Call, using the name and parameter matching if we did not associate
624651
* this call with a specific definition at link or compile time, and performing simple virtual
625652
* dispatch resolution.
626653
*/
627654
Function getTarget(Call c) {
628-
if VirtualDispatch::getAViableTarget(c).isDefined()
629-
then
630-
/*
631-
* If there is at least one defined target after performing some simple virtual dispatch
632-
* resolution, then the result is all the defined targets.
633-
*/
634-
635-
result = VirtualDispatch::getAViableTarget(c) and
636-
result.isDefined()
637-
else
638-
if exists(getAPossibleDefinition(VirtualDispatch::getAViableTarget(c)))
639-
then
640-
/*
641-
* If we can use the heuristic matching of functions to find definitions for some of the viable
642-
* targets, return those.
643-
*/
644-
645-
result = getAPossibleDefinition(VirtualDispatch::getAViableTarget(c))
646-
else
647-
// Otherwise, the result is the undefined `Function` instances
648-
result = VirtualDispatch::getAViableTarget(c)
655+
result = getTarget1(c) or
656+
result = getTarget2(c) or
657+
result = getTarget3(c)
649658
}
650659

651660
/**

0 commit comments

Comments
 (0)