tst-malloc-usable.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Ensure that malloc_usable_size returns the request size with
  2. MALLOC_CHECK_ exported to a positive value.
  3. Copyright (C) 2012-2026 Free Software Foundation, Inc.
  4. Copyright The GNU Toolchain Authors.
  5. This file is part of the GNU C Library.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. 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.
  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/>. */
  17. #include <malloc.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <support/support.h>
  21. #include <support/check.h>
  22. static int
  23. do_test (void)
  24. {
  25. size_t usable_size;
  26. void *p = malloc (7);
  27. TEST_VERIFY_EXIT (p != NULL);
  28. usable_size = malloc_usable_size (p);
  29. TEST_COMPARE (usable_size, 7);
  30. memset (p, 0, usable_size);
  31. free (p);
  32. TEST_COMPARE (malloc_usable_size (NULL), 0);
  33. return 0;
  34. }
  35. #include "support/test-driver.c"