1 /* Copyright (C) 2005-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <libc-diag.h>
24 static int errors
= 0;
27 merror (const char *msg
)
30 printf ("Error: %s\n", msg
);
40 DIAG_PUSH_NEEDS_COMMENT
;
41 #if __GNUC_PREREQ (7, 0)
42 /* GCC 7 warns about too-large allocations; here we want to test
44 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
47 DIAG_POP_NEEDS_COMMENT
;
50 merror ("malloc (-1) succeeded.");
51 else if (errno
!= ENOMEM
)
52 merror ("errno is not set correctly.");
56 merror ("malloc (10) failed.");
60 merror ("realloc (p, 0) failed.");
64 merror ("malloc (0) failed.");
68 merror ("realloc (p, 0) failed.");
72 merror ("malloc (256) failed.");
76 merror ("malloc (512) failed.");
78 DIAG_PUSH_NEEDS_COMMENT
;
79 #if __GNUC_PREREQ (7, 0)
80 /* GCC 7 warns about too-large allocations; here we want to test
82 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
84 if (realloc (p
, -256) != NULL
)
85 merror ("realloc (p, -256) succeeded.");
86 else if (errno
!= ENOMEM
)
87 merror ("errno is not set correctly.");
88 DIAG_POP_NEEDS_COMMENT
;
94 merror ("malloc (512) failed.");
96 DIAG_PUSH_NEEDS_COMMENT
;
97 #if __GNUC_PREREQ (7, 0)
98 /* GCC 7 warns about too-large allocations; here we want to test
100 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
102 if (realloc (p
, -1) != NULL
)
103 merror ("realloc (p, -1) succeeded.");
104 else if (errno
!= ENOMEM
)
105 merror ("errno is not set correctly.");
106 DIAG_POP_NEEDS_COMMENT
;
114 #define TEST_FUNCTION do_test ()
115 #include "../test-skeleton.c"