>From 3189c490ec29a74e91e1b800d63fb7c9f9b47d2b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 9 May 2021 18:34:58 +0200 Subject: [PATCH 1/2] 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. --- ChangeLog | 9 +++++++++ tests/test-calloc-gnu.c | 6 ++++-- tests/test-malloc-gnu.c | 4 +++- tests/test-realloc-gnu.c | 4 +++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e84bc51..e69f447 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 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. * lib/getrandom.c (getrandom): When open() fails, set errno to ENOSYS. diff --git a/tests/test-calloc-gnu.c b/tests/test-calloc-gnu.c index b46e788..dbef019 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 d8e7b04..13217c1 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 f4c00c0..a366738 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; } -- 2.7.4