CPP: Add test cases.

This commit is contained in:
Geoffrey White
2019-01-24 10:18:13 +00:00
parent 47ad280e34
commit 23ae12a763
2 changed files with 43 additions and 0 deletions

View File

@@ -2,3 +2,4 @@
| test.cpp:182:3:182:22 | delete | This memory may have been allocated with '$@', not 'new'. | test.cpp:175:18:175:29 | new[] | new[] |
| test.cpp:240:2:240:9 | delete | This memory may have been allocated with '$@', not 'new'. | test.cpp:228:7:228:17 | new[] | new[] |
| test.cpp:295:2:295:11 | delete | This memory may have been allocated with '$@', not 'new'. | test.cpp:290:8:290:28 | new[] | new[] |
| test.cpp:310:3:310:13 | delete | This memory may have been allocated with '$@', not 'new'. | test.cpp:304:18:304:29 | new[] | new[] |

View File

@@ -295,3 +295,45 @@ static void map_shutdown()
delete map; // BAD: new[] -> delete
map = 0;
}
// ---
class Test10
{
public:
Test10() : data(new char[10])
{
}
~Test10()
{
delete data; // BAD: new[] -> delete
}
char *data;
};
class Test11
{
public:
Test11()
{
data = new char[10];
}
void resize(int size)
{
if (size > 0)
{
delete [] data; // GOOD
data = new char[size];
}
}
~Test11()
{
delete data; // BAD: new[] -> delete [NOT DETECTED]
}
char *data;
};