diff options
-rw-r--r-- | configure.ac | 19 | ||||
-rw-r--r-- | openbsd-compat/bsd-malloc.c | 2 |
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 | |||
1337 | AC_FUNC_MALLOC | 1337 | AC_FUNC_MALLOC |
1338 | AC_FUNC_REALLOC | 1338 | AC_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; |
1340 | if test "x$ac_cv_func_malloc_0_nonnull" != "xyes"; then | 1340 | AC_MSG_CHECKING([if calloc(0, N) returns non-null]) |
1341 | AC_DEFINE(HAVE_CALLOC, 0, [calloc(x, 0) returns NULL]) | 1341 | AC_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 | ) | ||
1351 | AC_MSG_RESULT([$func_calloc_0_nonnull]) | ||
1352 | |||
1353 | if test "x$func_calloc_0_nonnull" == "xyes"; then | ||
1354 | AC_DEFINE(HAVE_CALLOC, 1, [calloc(0, x) returns non-null]) | ||
1355 | else | ||
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.]) |
1344 | fi | 1359 | fi |
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 |