Skip to content

Commit faeb326

Browse files
committed
CPP: Use newer dataflow for the fix.
1 parent 7d8886e commit faeb326

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

cpp/ql/src/Critical/NewDelete.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import cpp
55
import semmle.code.cpp.controlflow.SSA
6+
import semmle.code.cpp.dataflow.DataFlow
67

78
/**
89
* Holds if `alloc` is a use of `malloc` or `new`. `kind` is
@@ -46,10 +47,9 @@ predicate allocExprOrIndirect(Expr alloc, string kind) {
4647
alloc.(FunctionCall).getTarget() = rtn.getEnclosingFunction() and
4748
(
4849
allocExprOrIndirect(rtn.getExpr(), kind) or
49-
exists(SsaDefinition def, LocalScopeVariable v |
50-
// alloc via SSA
51-
allocExprOrIndirect(def.getAnUltimateDefiningValue(v), kind) and
52-
rtn.getExpr() = def.getAUse(v)
50+
exists(Expr e |
51+
allocExprOrIndirect(e, kind) and
52+
DataFlow::localFlow(DataFlow::exprNode(e), DataFlow::exprNode(rtn.getExpr()))
5353
)
5454
)
5555
)

cpp/ql/test/query-tests/Critical/NewFree/NewFreeMismatch.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| test.cpp:91:3:91:11 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:88:28:88:36 | call to my_malloc | malloc |
77
| test.cpp:99:3:99:11 | call to my_delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:96:28:96:33 | call to malloc | malloc |
88
| test.cpp:138:2:138:9 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:135:12:135:22 | call to my_malloc_2 | malloc |
9+
| test.cpp:155:2:155:9 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:152:12:152:22 | call to my_malloc_3 | malloc |
910
| test.cpp:232:2:232:9 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:226:7:226:12 | call to malloc | malloc |
1011
| test.cpp:233:2:233:12 | delete[] | There is a malloc/delete mismatch between this delete[] and the corresponding $@. | test.cpp:226:7:226:12 | call to malloc | malloc |
1112
| test.cpp:235:2:235:5 | call to free | There is a new/free mismatch between this free and the corresponding $@. | test.cpp:227:7:227:13 | new | new |

cpp/ql/test/query-tests/Critical/NewFree/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void test3()
152152
void *b = my_malloc_3(10);
153153

154154
free(a); // GOOD
155-
delete b; // BAD: malloc -> delete [NOT DETECTED]
155+
delete b; // BAD: malloc -> delete
156156
}
157157

158158
void test4(bool do_array_delete)

0 commit comments

Comments
 (0)