1.1 --- a/test/mpool_tests.c Tue Jan 02 17:00:21 2018 +0100 1.2 +++ b/test/mpool_tests.c Sun Jan 21 10:13:21 2018 +0100 1.3 @@ -75,6 +75,13 @@ 1.4 1.5 UCX_TEST_ASSERT(*test == 5, "wrong pointer"); 1.6 1.7 + // overflow test 1.8 + void *n0 = ucx_mempool_malloc(pool, (size_t)-1); 1.9 + void *n1 = ucx_mempool_malloc(pool, ((size_t)-1) - sizeof(void*)/2); 1.10 + 1.11 + UCX_TEST_ASSERT(n0 == NULL, "should not allocate SIZE_MAX bytes"); 1.12 + UCX_TEST_ASSERT(n1 == NULL, "should detect integer overflow"); 1.13 + 1.14 UCX_TEST_END 1.15 ucx_mempool_destroy(pool); 1.16 } 1.17 @@ -89,6 +96,13 @@ 1.18 UCX_TEST_ASSERT(test != NULL, "no memory for test data"); 1.19 UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed"); 1.20 1.21 + // overflow test 1.22 + void *n0 = ucx_mempool_calloc(pool, (size_t)-1, 1); 1.23 + void *n1 = ucx_mempool_calloc(pool, ((size_t)-1)/2, 3); 1.24 + 1.25 + UCX_TEST_ASSERT(n0 == NULL, "should not allocate SIZE_MAX bytes"); 1.26 + UCX_TEST_ASSERT(n1 == NULL, "should detect integer overflow"); 1.27 + 1.28 UCX_TEST_END 1.29 ucx_mempool_destroy(pool); 1.30 }