tst-malloc-usable.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Ensure that malloc_usable_size returns the request size with
  2. MALLOC_CHECK_ exported to a positive value.
  3. Copyright (C) 2012-2019 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  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.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <malloc.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. static int
  20. do_test (void)
  21. {
  22. size_t usable_size;
  23. void *p = malloc (7);
  24. if (!p)
  25. {
  26. printf ("memory allocation failed\n");
  27. return 1;
  28. }
  29. usable_size = malloc_usable_size (p);
  30. if (usable_size != 7)
  31. {
  32. printf ("malloc_usable_size: expected 7 but got %zu\n", usable_size);
  33. return 1;
  34. }
  35. memset (p, 0, usable_size);
  36. free (p);
  37. return 0;
  38. }
  39. #define TEST_FUNCTION do_test ()
  40. #include "../test-skeleton.c"