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

Skip to content

Commit cd13e58

Browse files
committed
CPP: Performance improvement.
1 parent 7b0f310 commit cd13e58

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

cpp/ql/src/Critical/NewDelete.qll

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,27 @@ predicate allocExprOrIndirect(Expr alloc, string kind) {
5151
)
5252
}
5353

54+
/**
55+
* Holds if `v` is assigned value `e`, and `e` is not known to be `0`.
56+
*/
57+
private predicate nonNullGlobalAssignment(Variable v, Expr e) {
58+
not v instanceof LocalScopeVariable and
59+
v.getAnAssignedValue() = e and
60+
not e.getValue().toInt() = 0
61+
}
62+
5463
/**
5564
* Holds if `v` is a non-local variable which is assigned only with allocations of
5665
* type `kind` (it may also be assigned with NULL).
5766
*/
5867
private predicate allocReachesVariable(Variable v, Expr alloc, string kind) {
59-
not v instanceof LocalScopeVariable and
6068
exists(Expr mid |
61-
v.getAnAssignedValue() = mid and
69+
nonNullGlobalAssignment(v, mid) and
6270
allocReaches(mid, alloc, kind)
63-
) and forall(Expr mid |
64-
v.getAnAssignedValue() = mid |
65-
allocReaches(mid, _, kind) or
66-
mid.getValue().toInt() = 0 // NULL
71+
) and
72+
forall(Expr mid |
73+
nonNullGlobalAssignment(v, mid) |
74+
allocReaches(mid, _, kind)
6775
)
6876
}
6977

0 commit comments

Comments
 (0)