aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Barnes <craigbarnes@protonmail.com>2020-08-25 19:49:24 +0000
committerCraig Barnes <craigbarnes@protonmail.com>2020-08-25 19:49:24 +0000
commitfe9eaf3aafe11428d630bb52bdfa5963f8f456b0 (patch)
tree576792a5a3fcdaac9b4f97a91f36f5b87d986dce
parentMerge branch 'type-limit-fixes' into master (diff)
xmalloc: fix edge case handling in xcalloc() function
-rw-r--r--xmalloc.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/xmalloc.c b/xmalloc.c
index ebac8a1d..c90b97dc 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
@@ -36,10 +37,8 @@ xmalloc(size_t size)
void *
xcalloc(size_t nmemb, size_t size)
{
- if (unlikely(nmemb == 0 || size == 0)) {
- size = 1;
- }
- return check_alloc(calloc(nmemb, size));
+ assert(size != 0);
+ return check_alloc(calloc(likely(nmemb) ? nmemb : 1, size));
}
void *