]>
Commit | Line | Data |
---|---|---|
6ef9cc37 SP |
1 | /* Ensure that malloc_usable_size returns the request size with |
2 | MALLOC_CHECK_ exported to a positive value. | |
3 | ||
581c785b | 4 | Copyright (C) 2012-2022 Free Software Foundation, Inc. |
88e316b0 | 5 | Copyright The GNU Toolchain Authors. |
6ef9cc37 SP |
6 | This file is part of the GNU C Library. |
7 | ||
8 | The GNU C Library is free software; you can redistribute it and/or | |
9 | modify it under the terms of the GNU Lesser General Public | |
10 | License as published by the Free Software Foundation; either | |
11 | version 2.1 of the License, or (at your option) any later version. | |
12 | ||
13 | The GNU C Library is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public | |
19 | License along with the GNU C Library; if not, see | |
5a82c748 | 20 | <https://www.gnu.org/licenses/>. */ |
6ef9cc37 SP |
21 | |
22 | #include <malloc.h> | |
23 | #include <string.h> | |
24 | #include <stdio.h> | |
88e316b0 SP |
25 | #include <support/support.h> |
26 | #include <support/check.h> | |
6ef9cc37 SP |
27 | |
28 | static int | |
29 | do_test (void) | |
30 | { | |
31 | size_t usable_size; | |
32 | void *p = malloc (7); | |
6ef9cc37 | 33 | |
88e316b0 | 34 | TEST_VERIFY_EXIT (p != NULL); |
6ef9cc37 | 35 | usable_size = malloc_usable_size (p); |
88e316b0 | 36 | TEST_COMPARE (usable_size, 7); |
6ef9cc37 SP |
37 | memset (p, 0, usable_size); |
38 | free (p); | |
88e316b0 SP |
39 | |
40 | TEST_COMPARE (malloc_usable_size (NULL), 0); | |
41 | ||
6ef9cc37 SP |
42 | return 0; |
43 | } | |
44 | ||
88e316b0 | 45 | #include "support/test-driver.c" |