aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-10-03 02:22:09 -0700
committerMichael Forney <mforney@mforney.org>2021-10-03 02:22:09 -0700
commit6764a38d863103f6ca66bb05fbbe2be2225f973e (patch)
tree3da51ff6892069ee46f2ffacfd3f4903b1f9adfe
parentac369afb858c399ba05638eb115ad69d58f42b95 (diff)
downloadcproc-6764a38d863103f6ca66bb05fbbe2be2225f973e.tar.xz
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.
-rw-r--r--util.c4
1 files 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;