From: Paul Eggert Date: Sun, 30 May 2021 17:04:06 +0000 (-0700) Subject: reallocarray-tests: port to weird platforms X-Git-Tag: v1.0~2868 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c45faf7f48bcbe57df3bbf8df81a016c5f15df55;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 08f9c7b24c..a110970f3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2021-05-30 Paul Eggert + 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);