From e19068504d7997e1c4da4ce8f55304fa5f571625 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Tue, 16 Jul 2019 08:12:21 +0200 Subject: [PATCH] Configure xrealloc and adjust gnu memory functions (#2003) Remove tag, since the functions do not return unless there was no error. --- cfg/gnu.cfg | 6 ++---- test/cfg/gnu.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cfg/gnu.cfg b/cfg/gnu.cfg index bfcb20972..688145e2f 100644 --- a/cfg/gnu.cfg +++ b/cfg/gnu.cfg @@ -11,6 +11,8 @@ xmalloc xcalloc + xstrdup + xrealloc free @@ -48,7 +50,6 @@ - false 0: @@ -57,7 +58,6 @@ - false @@ -133,7 +133,6 @@ - false @@ -149,7 +148,6 @@ - false diff --git a/test/cfg/gnu.c b/test/cfg/gnu.c index a043f4144..db3531e3a 100644 --- a/test/cfg/gnu.c +++ b/test/cfg/gnu.c @@ -15,6 +15,11 @@ #include #endif +// Declaration necessary because there is no specific / portable header. +extern void *xcalloc(size_t nmemb, size_t size); +extern void *xmalloc(size_t size); +extern void *xrealloc(void *block, size_t newsize); + void resourceLeak_mkostemps(char *template, int suffixlen, int flags) { // cppcheck-suppress unreadVariable @@ -117,13 +122,23 @@ void bufferAccessOutOfBounds() // 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); + + char * pAlloc2 = xmalloc(4); + memset(pAlloc2, 0, 4); + // cppcheck-suppress bufferAccessOutOfBounds + memset(pAlloc2, 0, 5); + + pAlloc2 = xrealloc(pAlloc2, 10); + memset(pAlloc2, 0, 10); + // cppcheck-suppress bufferAccessOutOfBounds + memset(pAlloc2, 0, 11); + + free(pAlloc2); } void leakReturnValNotUsed()