[hackers] [sbase][PATCH] Realloc variants should not fail if the requested size is zero

From: Mattias Andrée <maandree_AT_kth.se>
Date: Thu, 17 Mar 2016 10:11:02 +0100

Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
---
 libutil/ealloc.c       | 2 +-
 libutil/reallocarray.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libutil/ealloc.c b/libutil/ealloc.c
index 320865d..5a3cce1 100644
--- a/libutil/ealloc.c
+++ b/libutil/ealloc.c
_AT_@ -60,7 +60,7 @@ void *
 enrealloc(int status, void *p, size_t size)
 {
 	p = realloc(p, size);
-	if (!p)
+	if (!p && size)
 		enprintf(status, "realloc: out of memory\n");
 	return p;
 }
diff --git a/libutil/reallocarray.c b/libutil/reallocarray.c
index c6e5219..b964626 100644
--- a/libutil/reallocarray.c
+++ b/libutil/reallocarray.c
_AT_@ -43,7 +43,7 @@ ereallocarray(void *optr, size_t nmemb, size_t size)
 {
 	void *p;
 
-	if (!(p = reallocarray(optr, nmemb, size)))
+	if (!(p = reallocarray(optr, nmemb, size)) && nmemb && size)
 		eprintf("reallocarray: out of memory\n");
 
 	return p;
-- 
2.7.3
Received on Thu Mar 17 2016 - 10:11:02 CET

This archive was generated by hypermail 2.3.0 : Thu Mar 17 2016 - 10:12:12 CET