diff -r 591473851c95 -r 3d80d425543b test/mpool_tests.c --- a/test/mpool_tests.c Tue Jan 02 17:00:21 2018 +0100 +++ b/test/mpool_tests.c Sun Jan 21 10:13:21 2018 +0100 @@ -75,6 +75,13 @@ UCX_TEST_ASSERT(*test == 5, "wrong pointer"); + // overflow test + void *n0 = ucx_mempool_malloc(pool, (size_t)-1); + void *n1 = ucx_mempool_malloc(pool, ((size_t)-1) - sizeof(void*)/2); + + UCX_TEST_ASSERT(n0 == NULL, "should not allocate SIZE_MAX bytes"); + UCX_TEST_ASSERT(n1 == NULL, "should detect integer overflow"); + UCX_TEST_END ucx_mempool_destroy(pool); } @@ -89,6 +96,13 @@ UCX_TEST_ASSERT(test != NULL, "no memory for test data"); UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed"); + // overflow test + void *n0 = ucx_mempool_calloc(pool, (size_t)-1, 1); + void *n1 = ucx_mempool_calloc(pool, ((size_t)-1)/2, 3); + + UCX_TEST_ASSERT(n0 == NULL, "should not allocate SIZE_MAX bytes"); + UCX_TEST_ASSERT(n1 == NULL, "should detect integer overflow"); + UCX_TEST_END ucx_mempool_destroy(pool); }