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:
16
ChangeLog
16
ChangeLog
@@ -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>
|
2021-05-14 Simon Josefsson <simon@josefsson.org>
|
||||||
|
|
||||||
valgrind-tests: Fix 'sh: yes: unknown operand' error.
|
valgrind-tests: Fix 'sh: yes: unknown operand' error.
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
Files:
|
Files:
|
||||||
tests/test-calloc-gnu.c
|
tests/test-calloc-gnu.c
|
||||||
|
tests/macros.h
|
||||||
|
|
||||||
Depends-on:
|
Depends-on:
|
||||||
stdint
|
stdint
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
Files:
|
Files:
|
||||||
tests/test-malloc-gnu.c
|
tests/test-malloc-gnu.c
|
||||||
|
tests/macros.h
|
||||||
|
|
||||||
Depends-on:
|
Depends-on:
|
||||||
stdint
|
stdint
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
Files:
|
Files:
|
||||||
tests/test-realloc-gnu.c
|
tests/test-realloc-gnu.c
|
||||||
|
tests/macros.h
|
||||||
|
|
||||||
Depends-on:
|
Depends-on:
|
||||||
stdint
|
stdint
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
Files:
|
Files:
|
||||||
tests/test-reallocarray.c
|
tests/test-reallocarray.c
|
||||||
tests/signature.h
|
tests/signature.h
|
||||||
|
tests/macros.h
|
||||||
|
|
||||||
Depends-on:
|
Depends-on:
|
||||||
stdint
|
stdint
|
||||||
|
@@ -16,11 +16,14 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
/* Specification. */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
/* Return N.
|
/* Return N.
|
||||||
Usual compilers are not able to infer something about the return value. */
|
Usual compilers are not able to infer something about the return value. */
|
||||||
static size_t
|
static size_t
|
||||||
@@ -44,8 +47,7 @@ main ()
|
|||||||
/* Check that calloc (0, 0) is not a NULL pointer. */
|
/* Check that calloc (0, 0) is not a NULL pointer. */
|
||||||
{
|
{
|
||||||
void * volatile p = calloc (0, 0);
|
void * volatile p = calloc (0, 0);
|
||||||
if (p == NULL)
|
ASSERT (p != NULL);
|
||||||
return 1;
|
|
||||||
free (p);
|
free (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,11 +60,12 @@ main ()
|
|||||||
for (size_t n = 2; n != 0; n <<= 1)
|
for (size_t n = 2; n != 0; n <<= 1)
|
||||||
{
|
{
|
||||||
void *volatile p = calloc (PTRDIFF_MAX / n + 1, identity (n));
|
void *volatile p = calloc (PTRDIFF_MAX / n + 1, identity (n));
|
||||||
if (!(p == NULL && errno == ENOMEM))
|
ASSERT (p == NULL);
|
||||||
return 2;
|
ASSERT (errno == ENOMEM);
|
||||||
|
|
||||||
p = calloc (SIZE_MAX / n + 1, identity (n));
|
p = calloc (SIZE_MAX / n + 1, identity (n));
|
||||||
if (!(p == NULL && errno == ENOMEM))
|
ASSERT (p == NULL);
|
||||||
return 3;
|
ASSERT (errno == ENOMEM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,18 +16,20 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
/* Specification. */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
/* Check that malloc (0) is not a NULL pointer. */
|
/* Check that malloc (0) is not a NULL pointer. */
|
||||||
void *volatile p = malloc (0);
|
void *volatile p = malloc (0);
|
||||||
if (p == NULL)
|
ASSERT (p != NULL);
|
||||||
return 1;
|
|
||||||
free (p);
|
free (p);
|
||||||
|
|
||||||
/* Check that malloc (n) fails when n exceeds PTRDIFF_MAX. */
|
/* Check that malloc (n) fails when n exceeds PTRDIFF_MAX. */
|
||||||
@@ -35,8 +37,8 @@ main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
size_t one = argc != 12345;
|
size_t one = argc != 12345;
|
||||||
p = malloc (PTRDIFF_MAX + one);
|
p = malloc (PTRDIFF_MAX + one);
|
||||||
if (!(p == NULL && errno == ENOMEM))
|
ASSERT (p == NULL);
|
||||||
return 1;
|
ASSERT (errno == ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -16,18 +16,20 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
/* Specification. */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
/* Check that realloc (NULL, 0) is not a NULL pointer. */
|
/* Check that realloc (NULL, 0) is not a NULL pointer. */
|
||||||
void *volatile p = realloc (NULL, 0);
|
void *volatile p = realloc (NULL, 0);
|
||||||
if (p == NULL)
|
ASSERT (p != NULL);
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* Check that realloc (p, n) fails when p is non-null and n exceeds
|
/* Check that realloc (p, n) fails when p is non-null and n exceeds
|
||||||
PTRDIFF_MAX. */
|
PTRDIFF_MAX. */
|
||||||
@@ -35,8 +37,8 @@ main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
size_t one = argc != 12345;
|
size_t one = argc != 12345;
|
||||||
p = realloc (p, PTRDIFF_MAX + one);
|
p = realloc (p, PTRDIFF_MAX + one);
|
||||||
if (!(p == NULL && errno == ENOMEM))
|
ASSERT (p == NULL);
|
||||||
return 1;
|
ASSERT (errno == ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
free (p);
|
free (p);
|
||||||
|
@@ -16,13 +16,17 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
/* Specification. */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "signature.h"
|
#include "signature.h"
|
||||||
SIGNATURE_CHECK (reallocarray, void *, (void *, size_t, size_t));
|
SIGNATURE_CHECK (reallocarray, void *, (void *, size_t, size_t));
|
||||||
|
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main ()
|
main ()
|
||||||
{
|
{
|
||||||
@@ -33,17 +37,13 @@ main ()
|
|||||||
void *volatile p = NULL;
|
void *volatile p = NULL;
|
||||||
|
|
||||||
p = reallocarray (p, PTRDIFF_MAX / n + 1, n);
|
p = reallocarray (p, PTRDIFF_MAX / n + 1, n);
|
||||||
if (p)
|
ASSERT (p == NULL);
|
||||||
return 1;
|
ASSERT (errno == ENOMEM);
|
||||||
if (errno != ENOMEM)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
p = reallocarray (p, SIZE_MAX / n + 1, n);
|
p = reallocarray (p, SIZE_MAX / n + 1, n);
|
||||||
if (p)
|
ASSERT (p == NULL);
|
||||||
return 3;
|
ASSERT (errno == ENOMEM
|
||||||
if (!(errno == ENOMEM
|
|| errno == EOVERFLOW /* NetBSD */);
|
||||||
|| errno == EOVERFLOW /* NetBSD */))
|
|
||||||
return 4;
|
|
||||||
|
|
||||||
/* Reallocarray should not crash with zero sizes. */
|
/* Reallocarray should not crash with zero sizes. */
|
||||||
p = reallocarray (p, 0, n);
|
p = reallocarray (p, 0, n);
|
||||||
|
Reference in New Issue
Block a user