File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-416/semmle/tests Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 7
7
| test.cpp:170:6:170:9 | data | Memory pointed to by 'data' may have been previously freed $@ | test.cpp:165:2:165:5 | call to free | here |
8
8
| test.cpp:193:6:193:9 | data | Memory pointed to by 'data' may have been previously freed $@ | test.cpp:191:3:191:6 | call to free | here |
9
9
| test.cpp:201:6:201:6 | x | Memory pointed to by 'x' may have been previously freed $@ | test.cpp:200:2:200:9 | delete | here |
10
+ | test.cpp:242:14:242:17 | data | Memory pointed to by 'data' may have been previously freed $@ | test.cpp:243:11:243:14 | call to free | here |
Original file line number Diff line number Diff line change @@ -234,3 +234,21 @@ void test17(int n, bool b) {
234
234
use (data); // GOOD
235
235
}
236
236
}
237
+
238
+ void test18 (int * array) {
239
+ char * data = (char *)malloc (10 * sizeof (char ));
240
+ for (int i = 0 ; i < 4 ; ++i) {
241
+ int b = array[i];
242
+ if (b) use (data); // BAD
243
+ if (!b) free (data);
244
+ }
245
+ }
246
+
247
+ void test19 (int * array) {
248
+ char * data = (char *)malloc (10 * sizeof (char ));
249
+ int b = array[0 ];
250
+ for (int i = 0 ; i < 4 ; ++i) {
251
+ if (b) use (data); // GOOD
252
+ if (!b) free (data);
253
+ }
254
+ }
You can’t perform that action at this time.
0 commit comments