2017-01-04 Joseph Myers <joseph@codesourcery.com>
+ * malloc/tst-malloc.c: Include <libc-internal.h>.
+ (do_test): Disable -Walloc-size-larger-than= around tests of
+ malloc with negative sizes.
+ * malloc/tst-mcheck.c: Include <libc-internal.h>.
+ (do_test): Disable -Walloc-size-larger-than= around tests of
+ malloc and realloc with negative sizes.
+ * malloc/tst-realloc.c: Include <libc-internal.h>.
+ (do_test): Disable -Walloc-size-larger-than= around tests of
+ realloc with negative sizes.
+
* math/libm-test.inc (TEST_COND_ibm128_libgcc): New macro.
(init_max_error) [TEST_COND_ibm128]: Increase maximum error
allowed to 16 ulps.
#include <errno.h>
#include <malloc.h>
#include <stdio.h>
+#include <libc-internal.h>
static int errors = 0;
errno = 0;
+ DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+ /* GCC 7 warns about too-large allocations; here we want to test
+ that they fail. */
+ DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
+#endif
p = malloc (-1);
+ DIAG_POP_NEEDS_COMMENT;
save = errno;
if (p != NULL)
if (p == NULL)
merror ("malloc (513K) failed.");
+ DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+ /* GCC 7 warns about too-large allocations; here we want to test
+ that they fail. */
+ DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
+#endif
q = malloc (-512 * 1024);
+ DIAG_POP_NEEDS_COMMENT;
if (q != NULL)
merror ("malloc (-512K) succeeded.");
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <libc-internal.h>
static int errors = 0;
errno = 0;
+ DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+ /* GCC 7 warns about too-large allocations; here we want to test
+ that they fail. */
+ DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
+#endif
p = malloc (-1);
+ DIAG_POP_NEEDS_COMMENT;
if (p != NULL)
merror ("malloc (-1) succeeded.");
if (p == NULL)
merror ("malloc (512) failed.");
+ DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+ /* GCC 7 warns about too-large allocations; here we want to test
+ that they fail. */
+ DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
+#endif
if (realloc (p, -256) != NULL)
merror ("realloc (p, -256) succeeded.");
else if (errno != ENOMEM)
merror ("errno is not set correctly.");
+ DIAG_POP_NEEDS_COMMENT;
free (p);
if (p == NULL)
merror ("malloc (512) failed.");
+ DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+ /* GCC 7 warns about too-large allocations; here we want to test
+ that they fail. */
+ DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
+#endif
if (realloc (p, -1) != NULL)
merror ("realloc (p, -1) succeeded.");
else if (errno != ENOMEM)
merror ("errno is not set correctly.");
+ DIAG_POP_NEEDS_COMMENT;
free (p);
free (q);
#include <malloc.h>
#include <stdio.h>
#include <string.h>
+#include <libc-internal.h>
static int errors = 0;
errno = 0;
/* realloc (NULL, ...) behaves similarly to malloc (C89). */
+ DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+ /* GCC 7 warns about too-large allocations; here we want to test
+ that they fail. */
+ DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
+#endif
p = realloc (NULL, -1);
+ DIAG_POP_NEEDS_COMMENT;
save = errno;
if (p != NULL)
merror ("first 16 bytes were not correct");
/* Check failed realloc leaves original untouched (C89). */
+ DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+ /* GCC 7 warns about too-large allocations; here we want to test
+ that they fail. */
+ DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
+#endif
c = realloc (p, -1);
+ DIAG_POP_NEEDS_COMMENT;
if (c != NULL)
merror ("realloc (p, -1) succeeded.");