/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#if SIZEOF_VOID_P == 8
#else
#endif
static void test_mempool_overflow(void)
{
test_begin("mempool overflow");
#if SIZEOF_VOID_P == 8
/* grow */
test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, 4294967296ULL, 4294967297ULL) == POINTER_CAST(18446744073709551615ULL));
test_assert(p_realloc_type(&test_pool, m2, char, 18446744073709551614ULL, 18446744073709551615ULL) == POINTER_CAST(18446744073709551615ULL));
test_assert(p_realloc_type(&test_pool, m3, uint32_t, 4611686018427387902ULL, 4611686018427387903ULL) == POINTER_CAST(18446744073709551612ULL));
/* shrink */
test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, 4294967297ULL, 4294967296ULL) == POINTER_CAST(18446744069414584320ULL));
test_assert(p_realloc_type(&test_pool, m2, char, 18446744073709551615ULL, 18446744073709551614ULL) == POINTER_CAST(18446744073709551614ULL));
test_assert(p_realloc_type(&test_pool, m3, uint32_t, 4611686018427387903ULL, 4611686018427387902ULL) == POINTER_CAST(18446744073709551608ULL));
/* grow */
test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, 65536, 65537) == POINTER_CAST(4294967295U));
test_assert(p_realloc_type(&test_pool, m2, char, 4294967294U, 4294967295U) == POINTER_CAST(4294967295U));
test_assert(p_realloc_type(&test_pool, m3, uint32_t, 1073741822U, 1073741823U) == POINTER_CAST(4294967292U));
/* shrink */
test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, 65537, 65536) == POINTER_CAST(4294901760U));
test_assert(p_realloc_type(&test_pool, m2, char, 4294967295U, 4294967294U) == POINTER_CAST(4294967294U));
test_assert(p_realloc_type(&test_pool, m3, uint32_t, 1073741823U, 1073741822U) == POINTER_CAST(4294967288U));
#else
#endif
test_end();
}
{
test_expect_fatal_string("memory allocation overflow");
#if SIZEOF_VOID_P == 8
switch(stage) {
case 0:
test_begin("fatal mempool overflow");
return FATAL_TEST_FAILURE;
case 1:
return FATAL_TEST_FAILURE;
case 2: /* grow */
return FATAL_TEST_FAILURE;
case 3:
return FATAL_TEST_FAILURE;
case 4: /* shrink */
return FATAL_TEST_FAILURE;
case 5:
return FATAL_TEST_FAILURE;
}
switch(stage) {
case 0:
test_begin("fatal mempool overflow");
return FATAL_TEST_FAILURE;
case 1:
return FATAL_TEST_FAILURE;
case 2: /* grow */
return FATAL_TEST_FAILURE;
case 3:
return FATAL_TEST_FAILURE;
case 4: /* shrink */
return FATAL_TEST_FAILURE;
case 5:
return FATAL_TEST_FAILURE;
}
#else
#endif
test_end();
return FATAL_TEST_FINISHED;
}
return POINTER_CAST(new_size);
}
};
.v = &test_pool_vfuncs,
.alloconly_pool = TRUE,
.datastack_pool = FALSE,
};
void test_mempool(void)
{
}