From 6764a38d863103f6ca66bb05fbbe2be2225f973e Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 3 Oct 2021 02:22:09 -0700 Subject: util: Don't error on NULL from malloc if requested size was 0 It is implementation-defined whether malloc returns NULL or some pointer when the size is 0, so we don't want to error out if the implementation chose NULL. --- util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index 63511a3..724752d 100644 --- a/util.c +++ b/util.c @@ -58,7 +58,7 @@ void * xreallocarray(void *buf, size_t n, size_t m) { buf = reallocarray(buf, n, m); - if (!buf) + if (!buf && n && m) fatal("reallocarray:"); return buf; @@ -70,7 +70,7 @@ xmalloc(size_t len) void *buf; buf = malloc(len); - if (!buf) + if (!buf && len) fatal("malloc:"); return buf; -- cgit v1.2.3