summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac19
-rw-r--r--openbsd-compat/bsd-malloc.c2
2 files changed, 19 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 03cc3f869..605844ba2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1337,8 +1337,23 @@ AC_FUNC_STRFTIME
1337AC_FUNC_MALLOC 1337AC_FUNC_MALLOC
1338AC_FUNC_REALLOC 1338AC_FUNC_REALLOC
1339# autoconf doesn't have AC_FUNC_CALLOC so fake it if malloc returns NULL; 1339# autoconf doesn't have AC_FUNC_CALLOC so fake it if malloc returns NULL;
1340if test "x$ac_cv_func_malloc_0_nonnull" != "xyes"; then 1340AC_MSG_CHECKING([if calloc(0, N) returns non-null])
1341 AC_DEFINE(HAVE_CALLOC, 0, [calloc(x, 0) returns NULL]) 1341AC_RUN_IFELSE(
1342 [AC_LANG_PROGRAM(
1343 [[ #include <stdlib.h> ]],
1344 [[ void *p = calloc(0, 1); exit(p == NULL); ]]
1345 )],
1346 [ func_calloc_0_nonnull=yes ],
1347 [ func_calloc_0_nonnull=no ],
1348 [ AC_MSG_WARN([cross compiling: assuming same as malloc])
1349 func_calloc_0_nonnull="$ac_cv_func_malloc_0_nonnull"]
1350)
1351AC_MSG_RESULT([$func_calloc_0_nonnull])
1352
1353if test "x$func_calloc_0_nonnull" == "xyes"; then
1354 AC_DEFINE(HAVE_CALLOC, 1, [calloc(0, x) returns non-null])
1355else
1356 AC_DEFINE(HAVE_CALLOC, 0, [calloc(0, x) returns NULL])
1342 AC_DEFINE(calloc, rpl_calloc, 1357 AC_DEFINE(calloc, rpl_calloc,
1343 [Define to rpl_calloc if the replacement function should be used.]) 1358 [Define to rpl_calloc if the replacement function should be used.])
1344fi 1359fi
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)
50{ 50{
51 if (size == 0) 51 if (size == 0)
52 size = 1; 52 size = 1;
53 if (ptr == 0)
54 return malloc(size);
53 return realloc(ptr, size); 55 return realloc(ptr, size);
54} 56}
55#endif 57#endif