| 1 | /* Ensure that malloc_usable_size returns the request size with |
| 2 | MALLOC_CHECK_ exported to a positive value. |
| 3 | |
| 4 | Copyright (C) 2012-2024 Free Software Foundation, Inc. |
| 5 | Copyright The GNU Toolchain Authors. |
| 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 |
| 20 | <https://www.gnu.org/licenses/>. */ |
| 21 | |
| 22 | #include <malloc.h> |
| 23 | #include <string.h> |
| 24 | #include <stdio.h> |
| 25 | #include <support/support.h> |
| 26 | #include <support/check.h> |
| 27 | |
| 28 | static int |
| 29 | do_test (void) |
| 30 | { |
| 31 | size_t usable_size; |
| 32 | void *p = malloc (size: 7); |
| 33 | |
| 34 | TEST_VERIFY_EXIT (p != NULL); |
| 35 | usable_size = malloc_usable_size (ptr: p); |
| 36 | TEST_COMPARE (usable_size, 7); |
| 37 | memset (p, 0, usable_size); |
| 38 | free (ptr: p); |
| 39 | |
| 40 | TEST_COMPARE (malloc_usable_size (NULL), 0); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | #include "support/test-driver.c" |
| 46 | |