aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/basic/alloc-util.c2
-rw-r--r--src/basic/alloc-util.h6
2 files changed, 4 insertions, 4 deletions
diff --git a/src/basic/alloc-util.c b/src/basic/alloc-util.c
index 405445eac..ab7a42c4e 100644
--- a/src/basic/alloc-util.c
+++ b/src/basic/alloc-util.c
@@ -12,7 +12,7 @@ void* memdup(const void *p, size_t l) {
assert(l == 0 || p);
- ret = malloc(l);
+ ret = malloc(l ?: 1);
if (!ret)
return NULL;
diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h
index 7d237720b..ff7a46793 100644
--- a/src/basic/alloc-util.h
+++ b/src/basic/alloc-util.h
@@ -12,7 +12,7 @@ typedef void (*free_func_t)(void *p);
#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n)))
-#define new0(t, n) ((t*) calloc((n), sizeof(t)))
+#define new0(t, n) ((t*) calloc((n) ?: 1, sizeof(t)))
#define newa(t, n) \
({ \
@@ -77,7 +77,7 @@ _malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t
if (size_multiply_overflow(size, need))
return NULL;
- return malloc(size * need);
+ return malloc(size * need ?: 1);
}
#if !HAVE_REALLOCARRAY
@@ -85,7 +85,7 @@ _alloc_(2, 3) static inline void *reallocarray(void *p, size_t need, size_t size
if (size_multiply_overflow(size, need))
return NULL;
- return realloc(p, size * need);
+ return realloc(p, size * need ?: 1);
}
#endif