harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit df1dac2e0b31d222d5143d432f46b4412434302a
parent 62d4204f21332d97ad7697f628eade9137e9c3bc
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Fri, 24 Jun 2022 23:53:21 +0200

fix x{re,c}alloc behavior with size=0

Calloc and realloc may return NULL during normal operation if
the requested size is 0.

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Msrc/util.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/util.c b/src/util.c @@ -63,7 +63,7 @@ void * xcalloc(size_t n, size_t s) { void *p = calloc(n, s); - if (!p) { + if (!p && s) { abort(); } return p; @@ -73,7 +73,7 @@ void * xrealloc(void *p, size_t s) { p = realloc(p, s); - if (!p) { + if (!p && s) { abort(); } return p;