Skip to content

Commit f03c99a

Browse files
authored
Merge pull request github#5835 from hmakholm/hmakholm/pr/blowup-fix
CPP: fix semi-unused variables in WrongInDetectingAndHandlingMemoryAllocationErrors.q
2 parents 95f26aa + 4964ce3 commit f03c99a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,27 @@ class WrongCheckErrorOperatorNew extends FunctionCall {
5353
* Holds if results call `operator new` check in `operator if`.
5454
*/
5555
predicate isExistsIfCondition() {
56-
exists(IfCompareWithZero ifc, AssignExpr aex, Initializer it |
56+
exists(IfCompareWithZero ifc |
5757
// call `operator new` directly from the condition of `operator if`.
5858
this = ifc.getCondition().getAChild*()
5959
or
60-
// check results call `operator new` with variable appropriation
6160
postDominates(ifc, this) and
62-
aex.getAChild() = exp and
63-
ifc.getCondition().getAChild().(VariableAccess).getTarget() =
64-
aex.getLValue().(VariableAccess).getTarget()
65-
or
66-
// check results call `operator new` with declaration variable
67-
postDominates(ifc, this) and
68-
exp = it.getExpr() and
69-
it.getDeclaration() = ifc.getCondition().getAChild().(VariableAccess).getTarget()
61+
exists(Variable v |
62+
v = ifc.getCondition().getAChild().(VariableAccess).getTarget() and
63+
(
64+
exists(AssignExpr aex |
65+
// check results call `operator new` with variable appropriation
66+
aex.getAChild() = exp and
67+
v = aex.getLValue().(VariableAccess).getTarget()
68+
)
69+
or
70+
exists(Initializer it |
71+
// check results call `operator new` with declaration variable
72+
exp = it.getExpr() and
73+
it.getDeclaration() = v
74+
)
75+
)
76+
)
7077
)
7178
}
7279

0 commit comments

Comments
 (0)