summaryrefslogtreecommitdiff
path: root/m4/calloc.m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-05-23 23:46:43 +0200
committerBruno Haible <bruno@clisp.org>2020-05-23 23:47:27 +0200
commitd5ea809c3c7063d0dd5f7b70de7430f5bd4b991a (patch)
tree04ca1f0961ae829f3dad00113d66e8154b1406a8 /m4/calloc.m4
parent3d29ad5500aca06b0f56bbe979b09c32017f6c1d (diff)
downloadgnulib-d5ea809c3c7063d0dd5f7b70de7430f5bd4b991a.tar.gz
calloc-gnu: Make the test work in non-flat address spaces.
Uses code by Paul Eggert. * m4/calloc.m4 (_AC_FUNC_CALLOC_IF): Allow a calloc() implementation to return more than SIZE_MAX bytes, but only without wrap-around bugs.
Diffstat (limited to 'm4/calloc.m4')
-rw-r--r--m4/calloc.m429
1 files changed, 20 insertions, 9 deletions
diff --git a/m4/calloc.m4 b/m4/calloc.m4
index a93439e8c8..f179a8a112 100644
--- a/m4/calloc.m4
+++ b/m4/calloc.m4
@@ -1,4 +1,4 @@
-# calloc.m4 serial 22
+# calloc.m4 serial 23
# Copyright (C) 2004-2020 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
@@ -38,16 +38,27 @@ AC_DEFUN([_AC_FUNC_CALLOC_IF],
AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT],
- [[int result = 0;
- char * volatile p = calloc ((size_t) -1 / 8 + 1, 8);
- if (!p)
- result |= 2;
- free (p);
+ [[int result;
+ typedef struct { char c[8]; } S8;
+ size_t n = (size_t) -1 / sizeof (S8) + 2;
+ S8 * volatile s = calloc (n, sizeof (S8));
+ if (s)
+ {
+ s[0].c[0] = 1;
+ if (s[n - 1].c[0])
+ result = 0;
+ else
+ result = 2;
+ }
+ else
+ result = 3;
+ free (s);
return result;
]])],
- dnl The exit code of this program is 0 if calloc() succeeded (which
- dnl it shouldn't), 2 if calloc() failed, or 1 if some leak sanitizer
- dnl terminated the program as a result of the calloc() call.
+ dnl The exit code of this program is 0 if calloc() succeeded with a
+ dnl wrap-around bug (which it shouldn't), 2 if calloc() succeeded in
+ dnl a non-flat address space, 3 if calloc() failed, or 1 if some leak
+ dnl sanitizer terminated the program as a result of the calloc() call.
[ac_cv_func_calloc_0_nonnull=no],
[])
else