test/mpool_tests.c

changeset 270
3d80d425543b
parent 259
2f5dea574a75
equal deleted inserted replaced
269:591473851c95 270:3d80d425543b
73 (intptr_t*)((char*)pool->data[1] + sizeof(ucx_destructor)); 73 (intptr_t*)((char*)pool->data[1] + sizeof(ucx_destructor));
74 *pooladdr = 5; 74 *pooladdr = 5;
75 75
76 UCX_TEST_ASSERT(*test == 5, "wrong pointer"); 76 UCX_TEST_ASSERT(*test == 5, "wrong pointer");
77 77
78 // overflow test
79 void *n0 = ucx_mempool_malloc(pool, (size_t)-1);
80 void *n1 = ucx_mempool_malloc(pool, ((size_t)-1) - sizeof(void*)/2);
81
82 UCX_TEST_ASSERT(n0 == NULL, "should not allocate SIZE_MAX bytes");
83 UCX_TEST_ASSERT(n1 == NULL, "should detect integer overflow");
84
78 UCX_TEST_END 85 UCX_TEST_END
79 ucx_mempool_destroy(pool); 86 ucx_mempool_destroy(pool);
80 } 87 }
81 88
82 UCX_TEST(test_ucx_mempool_calloc) { 89 UCX_TEST(test_ucx_mempool_calloc) {
86 93
87 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); 94 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
88 95
89 UCX_TEST_ASSERT(test != NULL, "no memory for test data"); 96 UCX_TEST_ASSERT(test != NULL, "no memory for test data");
90 UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed"); 97 UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed");
98
99 // overflow test
100 void *n0 = ucx_mempool_calloc(pool, (size_t)-1, 1);
101 void *n1 = ucx_mempool_calloc(pool, ((size_t)-1)/2, 3);
102
103 UCX_TEST_ASSERT(n0 == NULL, "should not allocate SIZE_MAX bytes");
104 UCX_TEST_ASSERT(n1 == NULL, "should detect integer overflow");
91 105
92 UCX_TEST_END 106 UCX_TEST_END
93 ucx_mempool_destroy(pool); 107 ucx_mempool_destroy(pool);
94 } 108 }
95 109

mercurial