1 /* Copyright (C) 2000-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>.
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 <http://www.gnu.org/licenses/>. */
25 #include <libc-diag.h>
28 /* Number of samples per size. */
38 for (i
= 0; i
< N
; ++i
)
42 ptrs
[i
] = (char *) calloc (1, size
);
47 for (j
= 0; j
< size
; ++j
)
49 if (ptrs
[i
][j
] != '\0')
50 error (EXIT_FAILURE
, 0,
51 "byte not cleared (size %d, element %d, byte %d)",
68 for (i
= 0; i
< N
; ++i
)
71 int n
= 1 + random () % 10;
72 int elem
= 1 + random () % 100;
75 ptrs
[i
] = (char *) calloc (n
, elem
);
80 for (j
= 0; j
< size
; ++j
)
82 if (ptrs
[i
][j
] != '\0')
83 error (EXIT_FAILURE
, 0,
84 "byte not cleared (size %d, element %d, byte %d)",
98 /* If the size is 0 the result is implementation defined. Just make
99 sure the program doesn't crash. The result of calloc is
100 deliberately ignored, so do not warn about that. */
101 DIAG_PUSH_NEEDS_COMMENT
;
102 DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result");
104 calloc (0, UINT_MAX
);
105 calloc (UINT_MAX
, 0);
106 calloc (0, ~((size_t) 0));
107 calloc (~((size_t) 0), 0);
108 DIAG_POP_NEEDS_COMMENT
;
115 /* We are allocating blocks with `calloc' and check whether every
116 block is completely cleared. We first try this for some fixed
117 times and then with random size. */
132 #define TEST_FUNCTION do_test ()
133 #include "../test-skeleton.c"