summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-05-30 10:04:06 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-05-30 10:04:47 -0700
commitc45faf7f48bcbe57df3bbf8df81a016c5f15df55 (patch)
tree0aadffebe9841b0519a4642330a209d9784104e3
parent2e1b7bf95c689b8532d5a87e91c94d11959e57aa (diff)
downloadgnulib-c45faf7f48bcbe57df3bbf8df81a016c5f15df55.tar.gz
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.
-rw-r--r--ChangeLog5
-rw-r--r--tests/test-reallocarray.c9
2 files changed, 11 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 08f9c7b24c..a110970f3a 100644
--- 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):
diff --git a/tests/test-reallocarray.c b/tests/test-reallocarray.c
index f0839ff748..ff90962a96 100644
--- a/tests/test-reallocarray.c
+++ b/tests/test-reallocarray.c
@@ -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);