From: Bruno Haible Date: Sun, 9 May 2021 16:34:58 +0000 (+0200) Subject: malloc-gnu, realloc-gnu, calloc-gnu tests: Verify errno is set. X-Git-Tag: v1.0~2903 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3189c490ec29a74e91e1b800d63fb7c9f9b47d2b;p=thirdparty%2Fgnulib.git malloc-gnu, realloc-gnu, calloc-gnu tests: Verify errno is set. * tests/test-malloc-gnu.c: Include . (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. --- diff --git a/ChangeLog b/ChangeLog index e84bc512eb..e69f4475b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2021-05-09 Bruno Haible + + malloc-gnu, realloc-gnu, calloc-gnu tests: Verify errno is set. + * tests/test-malloc-gnu.c: Include . + (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 getrandom: Fail with ENOSYS when the system has no randomness source. diff --git a/tests/test-calloc-gnu.c b/tests/test-calloc-gnu.c index b46e788136..dbef019143 100644 --- a/tests/test-calloc-gnu.c +++ b/tests/test-calloc-gnu.c @@ -17,6 +17,8 @@ #include #include + +#include #include /* 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; } } diff --git a/tests/test-malloc-gnu.c b/tests/test-malloc-gnu.c index d8e7b04a8f..13217c1b51 100644 --- a/tests/test-malloc-gnu.c +++ b/tests/test-malloc-gnu.c @@ -17,6 +17,8 @@ #include #include + +#include #include 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; } diff --git a/tests/test-realloc-gnu.c b/tests/test-realloc-gnu.c index f4c00c0bf7..a36673888b 100644 --- a/tests/test-realloc-gnu.c +++ b/tests/test-realloc-gnu.c @@ -17,6 +17,8 @@ #include #include + +#include #include 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; }