bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen uint32max_array_t *m1 = p_new(&test_pool, uint32max_array_t, 4294967297ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(m1 == POINTER_CAST(18446744073709551615ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen char *m2 = p_new(&test_pool, char, 18446744073709551615ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(m2 == POINTER_CAST(18446744073709551615ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen uint32_t *m3 = p_new(&test_pool, uint32_t, 4611686018427387903ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(m3 == POINTER_CAST(18446744073709551612ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, 4294967296ULL, 4294967297ULL) == POINTER_CAST(18446744073709551615ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m2, char, 18446744073709551614ULL, 18446744073709551615ULL) == POINTER_CAST(18446744073709551615ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m3, uint32_t, 4611686018427387902ULL, 4611686018427387903ULL) == POINTER_CAST(18446744073709551612ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, 4294967297ULL, 4294967296ULL) == POINTER_CAST(18446744069414584320ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m2, char, 18446744073709551615ULL, 18446744073709551614ULL) == POINTER_CAST(18446744073709551614ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m3, uint32_t, 4611686018427387903ULL, 4611686018427387902ULL) == POINTER_CAST(18446744073709551608ULL));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen uint32max_array_t *m1 = p_new(&test_pool, uint32max_array_t, 65537);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen char *m2 = p_new(&test_pool, char, 4294967295U);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen uint32_t *m3 = p_new(&test_pool, uint32_t, 1073741823U);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, 65536, 65537) == POINTER_CAST(4294967295U));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m2, char, 4294967294U, 4294967295U) == POINTER_CAST(4294967295U));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m3, uint32_t, 1073741822U, 1073741823U) == POINTER_CAST(4294967292U));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, 65537, 65536) == POINTER_CAST(4294901760U));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m2, char, 4294967295U, 4294967294U) == POINTER_CAST(4294967294U));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(p_realloc_type(&test_pool, m3, uint32_t, 1073741823U, 1073741822U) == POINTER_CAST(4294967288U));
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenenum fatal_test_state fatal_mempool(unsigned int stage)
ba1a5db879b08d2fefcb42160af67853cdfe7687Timo Sirainen test_expect_fatal_string("memory allocation overflow");
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m1 = p_new(&test_pool, uint32max_array_t, 4294967298ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m2 = p_new(&test_pool, uint32_t, 4611686018427387904ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m1 = p_realloc_type(&test_pool, m1, uint32max_array_t, 4294967297ULL, 4294967298ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m2 = p_realloc_type(&test_pool, m2, uint32_t, 4611686018427387903ULL, 4611686018427387904ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m1 = p_realloc_type(&test_pool, m1, uint32max_array_t, 4294967298ULL, 4294967297ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m2 = p_realloc_type(&test_pool, m2, uint32_t, 4611686018427387904ULL, 4611686018427387903ULL);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m1 = p_new(&test_pool, uint32max_array_t, 65538);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m2 = p_new(&test_pool, uint32_t, 1073741824U);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m1 = p_realloc_type(&test_pool, m1, uint32max_array_t, 65537, 65538);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m2 = p_realloc_type(&test_pool, m2, uint32_t, 1073741823U, 1073741824U);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m1 = p_realloc_type(&test_pool, m1, uint32max_array_t, 65538, 65537);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen m2 = p_realloc_type(&test_pool, m2, uint32_t, 1073741824U, 1073741823U);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic const char *pool_test_get_name(pool_t pool ATTR_UNUSED) { return "test"; }
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic void pool_test_ref(pool_t pool ATTR_UNUSED) { }
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic void pool_test_unref(pool_t *pool) { *pool = NULL; }
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic void *pool_test_malloc(pool_t pool ATTR_UNUSED, size_t size) { return POINTER_CAST(size); }
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic void pool_test_free(pool_t pool ATTR_UNUSED, void *mem ATTR_UNUSED) { }
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic void *pool_test_realloc(pool_t pool ATTR_UNUSED, void *mem ATTR_UNUSED,
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen size_t old_size ATTR_UNUSED, size_t new_size) {
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic void pool_test_clear(pool_t pool ATTR_UNUSED) { }
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic size_t pool_test_get_max_easy_alloc_size(pool_t pool ATTR_UNUSED) { return 12345; }
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic const struct pool_vfuncs test_pool_vfuncs = {