2
0

overflow.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "test/jemalloc_test.h"
  2. TEST_BEGIN(test_overflow)
  3. {
  4. unsigned nhchunks;
  5. size_t mib[4];
  6. size_t sz, miblen, max_size_class;
  7. void *p;
  8. sz = sizeof(unsigned);
  9. assert_d_eq(mallctl("arenas.nhchunks", &nhchunks, &sz, NULL, 0), 0,
  10. "Unexpected mallctl() error");
  11. miblen = sizeof(mib) / sizeof(size_t);
  12. assert_d_eq(mallctlnametomib("arenas.hchunk.0.size", mib, &miblen), 0,
  13. "Unexpected mallctlnametomib() error");
  14. mib[2] = nhchunks - 1;
  15. sz = sizeof(size_t);
  16. assert_d_eq(mallctlbymib(mib, miblen, &max_size_class, &sz, NULL, 0), 0,
  17. "Unexpected mallctlbymib() error");
  18. assert_ptr_null(malloc(max_size_class + 1),
  19. "Expected OOM due to over-sized allocation request");
  20. assert_ptr_null(malloc(SIZE_T_MAX),
  21. "Expected OOM due to over-sized allocation request");
  22. assert_ptr_null(calloc(1, max_size_class + 1),
  23. "Expected OOM due to over-sized allocation request");
  24. assert_ptr_null(calloc(1, SIZE_T_MAX),
  25. "Expected OOM due to over-sized allocation request");
  26. p = malloc(1);
  27. assert_ptr_not_null(p, "Unexpected malloc() OOM");
  28. assert_ptr_null(realloc(p, max_size_class + 1),
  29. "Expected OOM due to over-sized allocation request");
  30. assert_ptr_null(realloc(p, SIZE_T_MAX),
  31. "Expected OOM due to over-sized allocation request");
  32. free(p);
  33. }
  34. TEST_END
  35. int
  36. main(void)
  37. {
  38. return (test(
  39. test_overflow));
  40. }