From e9dede06e5bc582a4aeb5b1cd5a7a640d7de3609 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 25 Feb 2018 10:20:31 +1100 Subject: Handle calloc(0,x) where different from malloc. Configure assumes that if malloc(0) returns null then calloc(0,n) also does. On some old platforms (SunOS4) malloc behaves as expected (as determined by AC_FUNC_MALLOC) but calloc doesn't. Test for this at configure time and activate the replacement function if found, plus handle this case in rpl_calloc. --- openbsd-compat/bsd-malloc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'openbsd-compat/bsd-malloc.c') diff --git a/openbsd-compat/bsd-malloc.c b/openbsd-compat/bsd-malloc.c index 6402ab588..482facdc9 100644 --- a/openbsd-compat/bsd-malloc.c +++ b/openbsd-compat/bsd-malloc.c @@ -50,6 +50,8 @@ rpl_realloc(void *ptr, size_t size) { if (size == 0) size = 1; + if (ptr == 0) + return malloc(size); return realloc(ptr, size); } #endif -- cgit v1.2.3