diff mbox

test-skeleton.c (xrealloc): Support realloc-as-free

Message ID 20160623122346.877DC4027F857@oldenburg.str.redhat.com
State New
Headers show

Commit Message

Florian Weimer June 23, 2016, 12:23 p.m. UTC
If the requested size is zero, realloc returns NULL, but the
deallocation is still successful.

2016-06-23  Florian Weimer  <fweimer@redhat.com>

	* test-skeleton.c (xrealloc): Support deallocation with n == 0.

Comments

Mike Frysinger June 23, 2016, 12:45 p.m. UTC | #1
On 23 Jun 2016 14:23, Florian Weimer wrote:
> If the requested size is zero, realloc returns NULL, but the
> deallocation is still successful.

not exactly.  realloc(NULL, 0) will return a valid pointer (much
like malloc(NULL) will).  code relies on this to generate cookies.
-mike
diff mbox

Patch

diff --git a/test-skeleton.c b/test-skeleton.c
index 0be4af1..243cd94 100644
--- a/test-skeleton.c
+++ b/test-skeleton.c
@@ -110,7 +110,7 @@  static void *
 xrealloc (void *p, size_t n)
 {
   p = realloc (p, n);
-  if (p == NULL)
+  if (p == NULL && n > 0)
     oom_error ("realloc", n);
   return p;
 }