1 /* Copyright (C) 2000-2024 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/>. */
24 #include <libc-diag.h>
27 /* Number of samples per size. */
37 for (i
= 0; i
< N
; ++i
)
41 ptrs
[i
] = (char *) calloc (1, size
);
46 for (j
= 0; j
< size
; ++j
)
48 if (ptrs
[i
][j
] != '\0')
49 error (EXIT_FAILURE
, 0,
50 "byte not cleared (size %d, element %d, byte %d)",
67 for (i
= 0; i
< N
; ++i
)
70 int n
= 1 + random () % 10;
71 int elem
= 1 + random () % 100;
74 ptrs
[i
] = (char *) calloc (n
, elem
);
79 for (j
= 0; j
< size
; ++j
)
81 if (ptrs
[i
][j
] != '\0')
82 error (EXIT_FAILURE
, 0,
83 "byte not cleared (size %d, element %d, byte %d)",
97 /* If the size is 0 the result is implementation defined. Just make
98 sure the program doesn't crash. The result of calloc is
99 deliberately ignored, so do not warn about that. */
100 DIAG_PUSH_NEEDS_COMMENT
;
101 DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result");
103 calloc (0, UINT_MAX
);
104 calloc (UINT_MAX
, 0);
105 calloc (0, ~((size_t) 0));
106 calloc (~((size_t) 0), 0);
107 DIAG_POP_NEEDS_COMMENT
;
114 /* We are allocating blocks with `calloc' and check whether every
115 block is completely cleared. We first try this for some fixed
116 times and then with random size. */
131 #define TEST_FUNCTION do_test ()
132 #include "../test-skeleton.c"