1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2025-08-08 17:22:05 +03:00

*alloc-gnu tests: Use ASSERT macro.

* tests/test-malloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-calloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-realloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-reallocarray.c: Include "macros.h".
(main): Use ASSERT.
* modules/malloc-gnu-tests (Files): Add tests/macros.h.
* modules/calloc-gnu-tests (Files): Likewise.
* modules/realloc-gnu-tests (Files): Likewise.
* modules/reallocarray-tests (Files): Likewise.
This commit is contained in:
Bruno Haible
2021-05-14 15:35:24 +02:00
parent 37f49aa5bb
commit f6b9c58618
9 changed files with 51 additions and 24 deletions

View File

@@ -1,3 +1,19 @@
2021-05-14 Bruno Haible <bruno@clisp.org>
*alloc-gnu tests: Use ASSERT macro.
* tests/test-malloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-calloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-realloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-reallocarray.c: Include "macros.h".
(main): Use ASSERT.
* modules/malloc-gnu-tests (Files): Add tests/macros.h.
* modules/calloc-gnu-tests (Files): Likewise.
* modules/realloc-gnu-tests (Files): Likewise.
* modules/reallocarray-tests (Files): Likewise.
2021-05-14 Simon Josefsson <simon@josefsson.org>
valgrind-tests: Fix 'sh: yes: unknown operand' error.

View File

@@ -1,5 +1,6 @@
Files:
tests/test-calloc-gnu.c
tests/macros.h
Depends-on:
stdint

View File

@@ -1,5 +1,6 @@
Files:
tests/test-malloc-gnu.c
tests/macros.h
Depends-on:
stdint

View File

@@ -1,5 +1,6 @@
Files:
tests/test-realloc-gnu.c
tests/macros.h
Depends-on:
stdint

View File

@@ -1,6 +1,7 @@
Files:
tests/test-reallocarray.c
tests/signature.h
tests/macros.h
Depends-on:
stdint

View File

@@ -16,11 +16,14 @@
#include <config.h>
/* Specification. */
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
#include "macros.h"
/* Return N.
Usual compilers are not able to infer something about the return value. */
static size_t
@@ -44,8 +47,7 @@ main ()
/* Check that calloc (0, 0) is not a NULL pointer. */
{
void * volatile p = calloc (0, 0);
if (p == NULL)
return 1;
ASSERT (p != NULL);
free (p);
}
@@ -58,11 +60,12 @@ main ()
for (size_t n = 2; n != 0; n <<= 1)
{
void *volatile p = calloc (PTRDIFF_MAX / n + 1, identity (n));
if (!(p == NULL && errno == ENOMEM))
return 2;
p = calloc (SIZE_MAX / n + 1, identity (n));
if (!(p == NULL && errno == ENOMEM))
return 3;
ASSERT (p == NULL);
ASSERT (errno == ENOMEM);
p = calloc (SIZE_MAX / n + 1, identity (n));
ASSERT (p == NULL);
ASSERT (errno == ENOMEM);
}
}

View File

@@ -16,18 +16,20 @@
#include <config.h>
/* Specification. */
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
#include "macros.h"
int
main (int argc, char **argv)
{
/* Check that malloc (0) is not a NULL pointer. */
void *volatile p = malloc (0);
if (p == NULL)
return 1;
ASSERT (p != NULL);
free (p);
/* Check that malloc (n) fails when n exceeds PTRDIFF_MAX. */
@@ -35,8 +37,8 @@ main (int argc, char **argv)
{
size_t one = argc != 12345;
p = malloc (PTRDIFF_MAX + one);
if (!(p == NULL && errno == ENOMEM))
return 1;
ASSERT (p == NULL);
ASSERT (errno == ENOMEM);
}
return 0;

View File

@@ -16,18 +16,20 @@
#include <config.h>
/* Specification. */
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
#include "macros.h"
int
main (int argc, char **argv)
{
/* Check that realloc (NULL, 0) is not a NULL pointer. */
void *volatile p = realloc (NULL, 0);
if (p == NULL)
return 1;
ASSERT (p != NULL);
/* Check that realloc (p, n) fails when p is non-null and n exceeds
PTRDIFF_MAX. */
@@ -35,8 +37,8 @@ main (int argc, char **argv)
{
size_t one = argc != 12345;
p = realloc (p, PTRDIFF_MAX + one);
if (!(p == NULL && errno == ENOMEM))
return 1;
ASSERT (p == NULL);
ASSERT (errno == ENOMEM);
}
free (p);

View File

@@ -16,13 +16,17 @@
#include <config.h>
/* Specification. */
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
#include "signature.h"
SIGNATURE_CHECK (reallocarray, void *, (void *, size_t, size_t));
#include "macros.h"
int
main ()
{
@@ -33,17 +37,13 @@ main ()
void *volatile p = NULL;
p = reallocarray (p, PTRDIFF_MAX / n + 1, n);
if (p)
return 1;
if (errno != ENOMEM)
return 2;
ASSERT (p == NULL);
ASSERT (errno == ENOMEM);
p = reallocarray (p, SIZE_MAX / n + 1, n);
if (p)
return 3;
if (!(errno == ENOMEM
|| errno == EOVERFLOW /* NetBSD */))
return 4;
ASSERT (p == NULL);
ASSERT (errno == ENOMEM
|| errno == EOVERFLOW /* NetBSD */);
/* Reallocarray should not crash with zero sizes. */
p = reallocarray (p, 0, n);