mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
CPP: fix semi-unused variables in WrongInDetectingAndHandlingMemoryAllocationErrors.ql
The fact that `aex` and `it` was each used in just one disjunct of the exists() body caused the optimizer to generate perfectly horrible code, including a pointless cartesian product between them that caused the evaluation to blow up. Fix it such that each variable is logically scoped. That makes the compiler much happier.
This commit is contained in:
@@ -53,20 +53,27 @@ class WrongCheckErrorOperatorNew extends FunctionCall {
|
||||
* Holds if results call `operator new` check in `operator if`.
|
||||
*/
|
||||
predicate isExistsIfCondition() {
|
||||
exists(IfCompareWithZero ifc, AssignExpr aex, Initializer it |
|
||||
exists(IfCompareWithZero ifc |
|
||||
// call `operator new` directly from the condition of `operator if`.
|
||||
this = ifc.getCondition().getAChild*()
|
||||
or
|
||||
// check results call `operator new` with variable appropriation
|
||||
postDominates(ifc, this) and
|
||||
aex.getAChild() = exp and
|
||||
ifc.getCondition().getAChild().(VariableAccess).getTarget() =
|
||||
aex.getLValue().(VariableAccess).getTarget()
|
||||
or
|
||||
// check results call `operator new` with declaration variable
|
||||
postDominates(ifc, this) and
|
||||
exp = it.getExpr() and
|
||||
it.getDeclaration() = ifc.getCondition().getAChild().(VariableAccess).getTarget()
|
||||
exists(Variable v |
|
||||
v = ifc.getCondition().getAChild().(VariableAccess).getTarget() and
|
||||
(
|
||||
exists(AssignExpr aex |
|
||||
// check results call `operator new` with variable appropriation
|
||||
aex.getAChild() = exp and
|
||||
v = aex.getLValue().(VariableAccess).getTarget()
|
||||
)
|
||||
or
|
||||
exists(Initializer it |
|
||||
// check results call `operator new` with declaration variable
|
||||
exp = it.getExpr() and
|
||||
it.getDeclaration() = v
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user