]> Savannah Git Hosting - gnulib.git/commitdiff
calloc-gnu: Make the test work in non-flat address spaces.
authorBruno Haible <bruno@clisp.org>
Sat, 23 May 2020 21:46:43 +0000 (23:46 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 23 May 2020 21:47:27 +0000 (23:47 +0200)
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.

ChangeLog
m4/calloc.m4

index 004f069c3dd1b3aa75160774f9cd8d6ef396b9d3..a7101db80fbabdfa2ce6e897e2fcfb8180680bd3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-05-23  Bruno Haible  <bruno@clisp.org>
+
+       calloc-gnu: Make 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.
+
 2020-05-23  Bruno Haible  <bruno@clisp.org>
 
        calloc-gnu: Avoid wrong configure results with GCC's AddressSanitizer.
index a93439e8c8f4391084b54cd43c39fe96b2ab9c07..f179a8a11264f42122bf4dd891793315fefcb8a0 100644 (file)
@@ -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