diff options
author | Darren Tucker <dtucker@dtucker.net> | 2018-02-25 10:20:31 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@dtucker.net> | 2018-02-26 00:09:04 +1100 |
commit | e9dede06e5bc582a4aeb5b1cd5a7a640d7de3609 (patch) | |
tree | f149ff2fb7ff3d427cfd1e7fcee416e7922ada84 /configure.ac | |
parent | 2eb4041493fd2635ffdc64a852d02b38c4955e0b (diff) |
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.
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 19 |
1 files changed, 17 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 |