[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] reallocarray-tests: port to weird platforms
From: |
Paul Eggert |
Subject: |
[PATCH 2/2] reallocarray-tests: port to weird platforms |
Date: |
Sun, 30 May 2021 10:05:02 -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 | 5 +++++
tests/test-reallocarray.c | 9 ++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 08f9c7b24..a110970f3 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 f0839ff74..ff90962a9 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);
--
2.27.0