]> Savannah Git Hosting - gnulib.git/commitdiff
realloc-posix tests: Enhance tests.
authorBruno Haible <bruno@clisp.org>
Thu, 31 Oct 2024 19:54:45 +0000 (20:54 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 31 Oct 2024 19:54:45 +0000 (20:54 +0100)
* tests/test-realloc-posix.c (main): Check errno also after normal
failing realloc calls.

ChangeLog
tests/test-realloc-posix.c

index 8cc43c210d5fda6d01530f586dc8ba040e5b7d71..79df4886b7ef4877cf138e8a81e70d3ae0ad4637 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-10-31  Bruno Haible  <bruno@clisp.org>
+
+       realloc-posix tests: Enhance tests.
+       * tests/test-realloc-posix.c (main): Check errno also after normal
+       failing realloc calls.
+
 2024-10-31  Bruno Haible  <bruno@clisp.org>
 
        realloc-posix tests: Fix memory leak.
index 0deb78c6995592cfa50aca3400f96fb6b07819ac..804d8f24e559735084556ff1d1a2f65171d79ad1 100644 (file)
@@ -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;
 }