stdlib: Fix stdbit.h with -Wconversion for clang
[glibc.git] / malloc / tst-malloc-usable.c
blob35cb10b32438aa8a975df1a5064a83a3164f240b
1 /* Ensure that malloc_usable_size returns the request size with
2 MALLOC_CHECK_ exported to a positive value.
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.
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.
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.
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/>. */
22 #include <malloc.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <support/support.h>
26 #include <support/check.h>
28 static int
29 do_test (void)
31 size_t usable_size;
32 void *p = malloc (7);
34 TEST_VERIFY_EXIT (p != NULL);
35 usable_size = malloc_usable_size (p);
36 TEST_COMPARE (usable_size, 7);
37 memset (p, 0, usable_size);
38 free (p);
40 TEST_COMPARE (malloc_usable_size (NULL), 0);
42 return 0;
45 #include "support/test-driver.c"