malloc-gnu, realloc-gnu, calloc-gnu tests: Verify errno is set.
authorBruno Haible <bruno@clisp.org>
Sun, 9 May 2021 16:34:58 +0000 (18:34 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 May 2021 16:34:58 +0000 (18:34 +0200)
* tests/test-malloc-gnu.c: Include <errno.h>.
(main): Verify that, when an allocation larger than PTRDIFF_MAX failed,
errno is ENOMEM.
* tests/test-realloc-gnu.c: Likewise.
* tests/test-calloc-gnu.c: Likewise.

ChangeLog
tests/test-calloc-gnu.c
tests/test-malloc-gnu.c
tests/test-realloc-gnu.c

index e84bc512eb9b49c4d03e3417b43c7b985ed244eb..e69f4475b59e867f57cdca8ab418721c2eb53cd2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-05-09  Bruno Haible  <bruno@clisp.org>
+
+       malloc-gnu, realloc-gnu, calloc-gnu tests: Verify errno is set.
+       * tests/test-malloc-gnu.c: Include <errno.h>.
+       (main): Verify that, when an allocation larger than PTRDIFF_MAX failed,
+       errno is ENOMEM.
+       * tests/test-realloc-gnu.c: Likewise.
+       * tests/test-calloc-gnu.c: Likewise.
+
 2021-05-09  Bruno Haible  <bruno@clisp.org>
 
        getrandom: Fail with ENOSYS when the system has no randomness source.
index b46e7881369ec54723c46043504c1aa65c70e2b3..dbef019143f5f46406b4e502f3345b1c72be6a01 100644 (file)
@@ -17,6 +17,8 @@
 #include <config.h>
 
 #include <stdlib.h>
+
+#include <errno.h>
 #include <stdint.h>
 
 /* Return N.
@@ -56,10 +58,10 @@ main ()
     for (size_t n = 2; n != 0; n <<= 1)
       {
         void *volatile p = calloc (PTRDIFF_MAX / n + 1, identity (n));
-        if (p != NULL)
+        if (!(p == NULL && errno == ENOMEM))
           return 2;
         p = calloc (SIZE_MAX / n + 1, identity (n));
-        if (p != NULL)
+        if (!(p == NULL && errno == ENOMEM))
           return 3;
       }
   }
index d8e7b04a8f0ec4f2d2febd21fa7b180a8674e1ac..13217c1b5113109e8f83cfdcd68a38130e2766d5 100644 (file)
@@ -17,6 +17,8 @@
 #include <config.h>
 
 #include <stdlib.h>
+
+#include <errno.h>
 #include <stdint.h>
 
 int
@@ -33,7 +35,7 @@ main (int argc, char **argv)
     {
       size_t one = argc != 12345;
       p = malloc (PTRDIFF_MAX + one);
-      if (p != NULL)
+      if (!(p == NULL && errno == ENOMEM))
         return 1;
     }
 
index f4c00c0bf7b3b17d24b2598715ba3cacccfa9eb9..a36673888b3017ebffdda6cc0ebe18693149d1c9 100644 (file)
@@ -17,6 +17,8 @@
 #include <config.h>
 
 #include <stdlib.h>
+
+#include <errno.h>
 #include <stdint.h>
 
 int
@@ -33,7 +35,7 @@ main (int argc, char **argv)
     {
       size_t one = argc != 12345;
       p = realloc (p, PTRDIFF_MAX + one);
-      if (p != NULL)
+      if (!(p == NULL && errno == ENOMEM))
         return 1;
     }