/*
* GCC "-Walloc-size-larger-than" warning detects when one of the memory
* allocation functions is called with a size larger than the maximum size that
* they support. Here we want to explicitly test that the allocation functions
* do indeed fail properly when this is the case, which triggers the warning.
* Therefore we disable the warning for these tests.
*/
JEMALLOC_DIAGNOSTIC_PUSH
JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
expect_ptr_null(malloc(max_size_class + 1),
"Expected OOM due to over-sized allocation request");
expect_ptr_null(malloc(SIZE_T_MAX),
"Expected OOM due to over-sized allocation request");
expect_ptr_null(calloc(1, max_size_class + 1),
"Expected OOM due to over-sized allocation request");
expect_ptr_null(calloc(1, SIZE_T_MAX),
"Expected OOM due to over-sized allocation request");
p = malloc(1);
expect_ptr_not_null(p, "Unexpected malloc() OOM");
expect_ptr_null(realloc(p, max_size_class + 1),
"Expected OOM due to over-sized allocation request");
expect_ptr_null(realloc(p, SIZE_T_MAX),
"Expected OOM due to over-sized allocation request");
free(p);
}
TEST_END
/* Re-enable the "-Walloc-size-larger-than=" warning */
JEMALLOC_DIAGNOSTIC_POP