gnu.cfg: Add "buffer-size" attribute and tests for xcalloc().

This commit is contained in:
versat 2019-03-21 10:44:18 +01:00
parent 316475f79f
commit 7c09b0cfe0
2 changed files with 9 additions and 1 deletions

View File

@ -10,7 +10,7 @@
</memory>
<memory>
<alloc init="false" buffer-size="malloc">xmalloc</alloc>
<alloc init="true">xcalloc</alloc>
<alloc init="true" buffer-size="calloc">xcalloc</alloc>
<dealloc>free</dealloc>
</memory>
<!-- https://linux.die.net/man/3/backtrace -->

View File

@ -63,6 +63,14 @@ void bufferAccessOutOfBounds()
sethostname(buf, 2);
// cppcheck-suppress bufferAccessOutOfBounds
sethostname(buf, 4);
// Declaration necessary because there is no specific / portable header containing xcalloc.
extern void *xcalloc(size_t nmemb, size_t size);
char * pAlloc1 = xcalloc(2, 4);
memset(pAlloc1, 0, 8);
// cppcheck-suppress bufferAccessOutOfBounds
memset(pAlloc1, 0, 9);
free(pAlloc1);
}
void leakReturnValNotUsed()