]> Savannah Git Hosting - gnulib.git/commitdiff
reallocarray-tests: port to weird platforms
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 30 May 2021 17:04:06 +0000 (10:04 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 30 May 2021 17:04:47 +0000 (10:04 -0700)
* tests/test-reallocarray.c (main): Don’t assume that
PTRDIFF_MAX / 2 + 1 <= SIZE_MAX.  POSIX allows platforms
where this isn’t true, though I don’t know of any examples.

ChangeLog
tests/test-reallocarray.c

index 08f9c7b24c2c3ca6882840a3f8d92aefce5a9d5a..a110970f3a0b45adb179fc329efbc30dd7f63d95 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2021-05-30  Paul Eggert  <eggert@cs.ucla.edu>
 
+       reallocarray-tests: port to weird platforms
+       * tests/test-reallocarray.c (main): Don’t assume that
+       PTRDIFF_MAX / 2 + 1 <= SIZE_MAX.  POSIX allows platforms
+       where this isn’t true, though I don’t know of any examples.
+
        dfa, etc.: prefer xreallocarray to older name
        * lib/dfa.c (addtok_mb, realloc_trans_if_necessary, enlist):
        * lib/readtokens.c (readtokens):
index f0839ff748e7e9a6821babdcad34084420f6a34d..ff90962a96bf1da2d61ff1099bb2c9400e7f3ddf 100644 (file)
@@ -36,9 +36,12 @@ main ()
     {
       void *volatile p = NULL;
 
-      p = reallocarray (p, PTRDIFF_MAX / n + 1, n);
-      ASSERT (p == NULL);
-      ASSERT (errno == ENOMEM);
+      if (PTRDIFF_MAX / n + 1 <= SIZE_MAX)
+        {
+          p = reallocarray (p, PTRDIFF_MAX / n + 1, n);
+          ASSERT (p == NULL);
+          ASSERT (errno == ENOMEM);
+        }
 
       p = reallocarray (p, SIZE_MAX / n + 1, n);
       ASSERT (p == NULL);