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

Skip to content

Commit 23ae12a

Browse files
committed
CPP: Add test cases.
1 parent 47ad280 commit 23ae12a

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| test.cpp:182:3:182:22 | delete | This memory may have been allocated with '$@', not 'new'. | test.cpp:175:18:175:29 | new[] | new[] |
33
| test.cpp:240:2:240:9 | delete | This memory may have been allocated with '$@', not 'new'. | test.cpp:228:7:228:17 | new[] | new[] |
44
| test.cpp:295:2:295:11 | delete | This memory may have been allocated with '$@', not 'new'. | test.cpp:290:8:290:28 | new[] | new[] |
5+
| test.cpp:310:3:310:13 | delete | This memory may have been allocated with '$@', not 'new'. | test.cpp:304:18:304:29 | new[] | new[] |

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,45 @@ static void map_shutdown()
295295
delete map; // BAD: new[] -> delete
296296
map = 0;
297297
}
298+
299+
// ---
300+
301+
class Test10
302+
{
303+
public:
304+
Test10() : data(new char[10])
305+
{
306+
}
307+
308+
~Test10()
309+
{
310+
delete data; // BAD: new[] -> delete
311+
}
312+
313+
char *data;
314+
};
315+
316+
class Test11
317+
{
318+
public:
319+
Test11()
320+
{
321+
data = new char[10];
322+
}
323+
324+
void resize(int size)
325+
{
326+
if (size > 0)
327+
{
328+
delete [] data; // GOOD
329+
data = new char[size];
330+
}
331+
}
332+
333+
~Test11()
334+
{
335+
delete data; // BAD: new[] -> delete [NOT DETECTED]
336+
}
337+
338+
char *data;
339+
};

0 commit comments

Comments
 (0)