C++: Add a couple more test cases.

This commit is contained in:
Geoffrey White
2021-01-20 15:33:32 +00:00
parent d2dd19a293
commit 439fe41b0a

View File

@@ -319,3 +319,28 @@ unsigned char *noBadResize_4_1(unsigned char *buffer, size_t currentSize, size_t
return buffer;
}
unsigned char * badResize_5_2(unsigned char *buffer, size_t currentSize, size_t newSize, int cond)
{
// BAD: on unsuccessful call to realloc, we will lose a pointer to a valid memory block [NOT DETECTED]
if (currentSize < newSize)
{
buffer = (unsigned char *)realloc(buffer, newSize);
}
if (cond)
{
abort(); // irrelevant
}
return buffer;
}
unsigned char * badResize_5_1(unsigned char *buffer, size_t currentSize, size_t newSize, int cond)
{
// BAD: on unsuccessful call to realloc, we will lose a pointer to a valid memory block [NOT DETECTED]
if (currentSize < newSize)
{
buffer = (unsigned char *)realloc(buffer, newSize);
assert(cond); // irrelevant
}
return buffer;
}