Skip to content

Commit f0085ed

Browse files
committed
CPP: Additional test cases.
1 parent edba241 commit f0085ed

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
| 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 |
1313
| test.cpp:239:2:239:5 | call to free | There is a new/free mismatch between this free and the corresponding $@. | test.cpp:228:7:228:17 | new[] | new[] |
1414
| test.cpp:272:3:272:6 | call to free | There is a new/free mismatch between this free and the corresponding $@. | test.cpp:265:7:265:13 | new | new |
15+
| test.cpp:367:3:367:10 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:359:14:359:19 | call to malloc | malloc |
16+
| test.cpp:370:3:370:6 | call to free | There is a new/free mismatch between this free and the corresponding $@. | test.cpp:356:7:356:15 | new | new |

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,37 @@ class Test11
337337

338338
char *data;
339339
};
340+
341+
// ---
342+
343+
int *z;
344+
345+
void test12(bool cond)
346+
{
347+
int *x, *y;
348+
349+
x = new int();
350+
delete x; // GOOD
351+
x = (int *)malloc(sizeof(int));
352+
free(x); // GOOD
353+
354+
if (cond)
355+
{
356+
y = new int();
357+
z = new int();
358+
} else {
359+
y = (int *)malloc(sizeof(int));
360+
z = (int *)malloc(sizeof(int));
361+
}
362+
363+
// ...
364+
365+
if (cond)
366+
{
367+
delete y; // GOOD [FALSE POSITIVE]
368+
delete z; // GOOD
369+
} else {
370+
free(y); // GOOD [FALSE POSITIVE]
371+
free(z); // GOOD
372+
}
373+
}

0 commit comments

Comments
 (0)