mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
CPP: Add a test of placement new in CWE-772 (this case came up recently but has already been fixed).
This commit is contained in:
@@ -555,6 +555,20 @@ void test28()
|
||||
dostuff();
|
||||
}
|
||||
|
||||
// placement new
|
||||
void* operator new(size_t, void* p);
|
||||
|
||||
class MyClass29
|
||||
{
|
||||
};
|
||||
|
||||
void test29()
|
||||
{
|
||||
void *buf = malloc(sizeof(MyClass29)); // GOOD (freed)
|
||||
MyClass29 *p1 = new (buf) MyClass29(); // GOOD (not really an allocation)
|
||||
free(buf);
|
||||
}
|
||||
|
||||
// run tests
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -585,4 +599,5 @@ int main(int argc, char *argv[])
|
||||
test26();
|
||||
test27();
|
||||
test28();
|
||||
test29();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user