From: Bruno Haible Date: Thu, 31 Oct 2024 19:54:45 +0000 (+0100) Subject: realloc-posix tests: Enhance tests. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=cf3ce55dbb24d9438e4f7ba74646087be1b3288a;p=gnulib.git realloc-posix tests: Enhance tests. * tests/test-realloc-posix.c (main): Check errno also after normal failing realloc calls. --- diff --git a/ChangeLog b/ChangeLog index 8cc43c210d..79df4886b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-10-31 Bruno Haible + + realloc-posix tests: Enhance tests. + * tests/test-realloc-posix.c (main): Check errno also after normal + failing realloc calls. + 2024-10-31 Bruno Haible realloc-posix tests: Fix memory leak. diff --git a/tests/test-realloc-posix.c b/tests/test-realloc-posix.c index 0deb78c699..804d8f24e5 100644 --- a/tests/test-realloc-posix.c +++ b/tests/test-realloc-posix.c @@ -60,6 +60,24 @@ main (int argc, _GL_UNUSED char **argv) ASSERT (errno == ENOMEM); } + /* Check that realloc sets errno when it fails. + Do this only in 64-bit processes, because there are many bi-arch systems + nowadays where a 32-bit process can actually allocate 2 GiB of RAM. */ + if (sizeof (size_t) >= 8) + { + void *volatile r; + + errno = 0; + r = realloc (p, SIZE_MAX / 10); + ASSERT (r == NULL); + ASSERT (errno == ENOMEM); + + errno = 0; + r = realloc (p, SIZE_MAX / 3); + ASSERT (r == NULL); + ASSERT (errno == ENOMEM); + } + free (p); return test_exit_status; }