tests/test_allocator.c

changeset 1040
1ecf4dbbc60c
parent 985
68754c7de906
equal deleted inserted replaced
1039:ec62453fc8a6 1040:1ecf4dbbc60c
88 CX_TEST(test_allocator_default_reallocarray_overflow) { 88 CX_TEST(test_allocator_default_reallocarray_overflow) {
89 char *test = calloc(8, 1); 89 char *test = calloc(8, 1);
90 memcpy(test, "Test", 5); 90 memcpy(test, "Test", 5);
91 CX_TEST_DO { 91 CX_TEST_DO {
92 void *fail = cxReallocArray(cxDefaultAllocator, test, SIZE_MAX/2, 4); 92 void *fail = cxReallocArray(cxDefaultAllocator, test, SIZE_MAX/2, 4);
93 CX_TEST_ASSERT(errno == ENOMEM); 93 CX_TEST_ASSERT(errno == EOVERFLOW);
94 CX_TEST_ASSERT(fail == NULL); 94 CX_TEST_ASSERT(fail == NULL);
95 CX_TEST_ASSERT(0 == strcmp(test, "Test")); 95 CX_TEST_ASSERT(0 == strcmp(test, "Test"));
96 } 96 }
97 free(test); 97 free(test);
98 } 98 }
146 char *test = calloc(8, 1); 146 char *test = calloc(8, 1);
147 memcpy(test, "Test", 5); 147 memcpy(test, "Test", 5);
148 CX_TEST_DO { 148 CX_TEST_DO {
149 int ret = cxReallocateArray(cxDefaultAllocator, &test, SIZE_MAX/2, 4); 149 int ret = cxReallocateArray(cxDefaultAllocator, &test, SIZE_MAX/2, 4);
150 CX_TEST_ASSERT(ret != 0); 150 CX_TEST_ASSERT(ret != 0);
151 CX_TEST_ASSERT(errno == ENOMEM); 151 CX_TEST_ASSERT(errno == EOVERFLOW);
152 CX_TEST_ASSERT(test != NULL); 152 CX_TEST_ASSERT(test != NULL);
153 CX_TEST_ASSERT(0 == strcmp(test, "Test")); 153 CX_TEST_ASSERT(0 == strcmp(test, "Test"));
154 } 154 }
155 free(test); 155 free(test);
156 } 156 }
171 char *test = calloc(8, 1); 171 char *test = calloc(8, 1);
172 memcpy(test, "Test", 5); 172 memcpy(test, "Test", 5);
173 CX_TEST_DO { 173 CX_TEST_DO {
174 int ret = cx_reallocatearray(&test, SIZE_MAX/2, 4); 174 int ret = cx_reallocatearray(&test, SIZE_MAX/2, 4);
175 CX_TEST_ASSERT(ret != 0); 175 CX_TEST_ASSERT(ret != 0);
176 CX_TEST_ASSERT(errno == ENOMEM); 176 CX_TEST_ASSERT(errno == EOVERFLOW);
177 CX_TEST_ASSERT(test != NULL); 177 CX_TEST_ASSERT(test != NULL);
178 CX_TEST_ASSERT(0 == strcmp(test, "Test")); 178 CX_TEST_ASSERT(0 == strcmp(test, "Test"));
179 } 179 }
180 free(test); 180 free(test);
181 } 181 }

mercurial