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:
Geoffrey White
2019-02-19 12:36:20 +00:00
parent c974693b58
commit 7dd7bf346d

View File

@@ -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();
}