* 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 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.
Files:
tests/test-calloc-gnu.c
+tests/macros.h
Depends-on:
stdint
Files:
tests/test-malloc-gnu.c
+tests/macros.h
Depends-on:
stdint
Files:
tests/test-realloc-gnu.c
+tests/macros.h
Depends-on:
stdint
Files:
tests/test-reallocarray.c
tests/signature.h
+tests/macros.h
Depends-on:
stdint
#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
/* 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);
}
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);
}
}
#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. */
{
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;
#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. */
{
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);
#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 ()
{
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);