20 fputs(
"\n--------------------\n", stderr);
21 fputs(panicBuffer, stderr);
23 "To avoid memory allocation problems\n"
24 " - increase your swap space (see 'man 8 mkswap'),\n"
25 " - reduce the amount of data (used for the failing operation)\n"
26 " - or buy more memory.\n"
28 "The program will terminate now!\n\n",
35 sprintf(panicBuffer,
"Failed to allocate memory: %s", reason);
39 sprintf(panicBuffer,
"Failed to allocate memory (tried to get %zu bytes)", size);
45 sprintf(panicBuffer,
"Failed to allocate memory (tried to get %zu*%zu bytes)", nelem, elsize);
57 #if !defined(LEAKS_SANITIZED) && !defined(__clang__) && defined(ENABLE_CRASH_TESTS)
59 # define TEST_ALLOC_SEGFAULTS
62 #if defined(TEST_ALLOC_SEGFAULTS)
63 static size_t TOO_MUCH = 1;
65 static void alloc_too_much() { ARB_alloc<char>(TOO_MUCH); }
66 static void calloc_too_much() { ARB_calloc<char>(TOO_MUCH); }
72 static bool mem_is_cleared(
const char *mem,
size_t size) {
73 for (
size_t s = 0;
s<size; ++
s) {
74 if (mem[
s])
return false;
79 void TEST_allocators__crashtest() {
81 const int SIZE2 = 200;
109 #if defined(TEST_ALLOC_SEGFAULTS)
static __ATTR__NORETURN void alloc_failure_panic()
#define TEST_EXPECT(cond)
void GBK_terminate(const char *error) __ATTR__NORETURN
#define TEST_REJECT_NULL(n)
static char panicBuffer[500]
void ARB_recalloc(TYPE *&tgt, size_t oelem, size_t nelem)
void failed_to_allocate(const char *reason) __ATTR__NORETURN
fputs(TRACE_PREFIX, stderr)
#define TEST_EXPECT_NULL(n)
void ARB_realloc(TYPE *&tgt, size_t nelem)
#define TEST_EXPECT_SEGFAULT(cb)
GB_write_int const char s