Add generic C.UTF-8 locale (Bug 17318)
[glibc.git] / malloc / tst-malloc-check.c
blobe00a16e6494e6bf58c568b85a9fe3bd1084b84d3
1 /* Copyright (C) 2005-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <libc-diag.h>
23 static int errors = 0;
25 static void
26 merror (const char *msg)
28 ++errors;
29 printf ("Error: %s\n", msg);
32 static int
33 do_test (void)
35 void *p, *q;
37 errno = 0;
39 DIAG_PUSH_NEEDS_COMMENT;
40 #if __GNUC_PREREQ (7, 0)
41 /* GCC 7 warns about too-large allocations; here we want to test
42 that they fail. */
43 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
44 #endif
45 p = malloc (-1);
46 DIAG_POP_NEEDS_COMMENT;
48 if (p != NULL)
49 merror ("malloc (-1) succeeded.");
50 else if (errno != ENOMEM)
51 merror ("errno is not set correctly.");
53 p = malloc (10);
54 if (p == NULL)
55 merror ("malloc (10) failed.");
57 p = realloc (p, 0);
58 if (p != NULL)
59 merror ("realloc (p, 0) failed.");
61 p = malloc (0);
62 if (p == NULL)
63 merror ("malloc (0) failed.");
65 p = realloc (p, 0);
66 if (p != NULL)
67 merror ("realloc (p, 0) failed.");
69 q = malloc (256);
70 if (q == NULL)
71 merror ("malloc (256) failed.");
73 p = malloc (512);
74 if (p == NULL)
75 merror ("malloc (512) failed.");
77 DIAG_PUSH_NEEDS_COMMENT;
78 #if __GNUC_PREREQ (7, 0)
79 /* GCC 7 warns about too-large allocations; here we want to test
80 that they fail. */
81 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
82 #endif
83 if (realloc (p, -256) != NULL)
84 merror ("realloc (p, -256) succeeded.");
85 else if (errno != ENOMEM)
86 merror ("errno is not set correctly.");
87 DIAG_POP_NEEDS_COMMENT;
89 free (p);
91 p = malloc (512);
92 if (p == NULL)
93 merror ("malloc (512) failed.");
95 DIAG_PUSH_NEEDS_COMMENT;
96 #if __GNUC_PREREQ (7, 0)
97 /* GCC 7 warns about too-large allocations; here we want to test
98 that they fail. */
99 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
100 #endif
101 if (realloc (p, -1) != NULL)
102 merror ("realloc (p, -1) succeeded.");
103 else if (errno != ENOMEM)
104 merror ("errno is not set correctly.");
105 DIAG_POP_NEEDS_COMMENT;
107 free (p);
108 free (q);
110 return errors != 0;
113 #define TEST_FUNCTION do_test ()
114 #include "../test-skeleton.c"