@@ -87,11 +87,15 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
8787 our_free (p);
8888}
8989
90- void test_calloc (size_t nmemb, size_t size, int err, bool null)
90+ void test_calloc (void *(*calloc_fn)( size_t , size_t ), size_t nmemb, size_t size, int err, bool null)
9191{
92- printf (" calloc(%zu, %zu) combined size %zu\n " , nmemb, size, nmemb * size);
92+ printf (" calloc" );
93+ if (calloc_fn == our_calloc_conceal)
94+ printf (" _conceal" );
95+
96+ printf (" (%zu, %zu) combined size %zu\n " , nmemb, size, nmemb * size);
9397 errno = SUCCESS;
94- void * p = our_calloc (nmemb, size);
98+ void * p = calloc_fn (nmemb, size);
9599
96100 if (p != nullptr )
97101 {
@@ -157,7 +161,7 @@ int main(int argc, char** argv)
157161 check_result (size + 1 , 1 , our_malloc (size + 1 ), SUCCESS, false );
158162 }
159163
160- test_calloc (0 , 0 , SUCCESS, false );
164+ test_calloc (our_calloc, 0 , 0 , SUCCESS, false );
161165
162166 our_free (nullptr );
163167
@@ -173,10 +177,10 @@ int main(int argc, char** argv)
173177 if (overflow)
174178 break ;
175179
176- test_calloc (n, size, SUCCESS, false );
177- test_calloc (n, 0 , SUCCESS, false );
180+ test_calloc (our_calloc, n, size, SUCCESS, false );
181+ test_calloc (our_calloc, n, 0 , SUCCESS, false );
178182 }
179- test_calloc (0 , size, SUCCESS, false );
183+ test_calloc (our_calloc, 0 , size, SUCCESS, false );
180184 }
181185
182186 for (smallsizeclass_t sc = 0 ; sc < NUM_SMALL_SIZECLASSES; sc++)
@@ -210,6 +214,34 @@ int main(int argc, char** argv)
210214
211215 test_realloc (our_malloc (64 ), 4194304 , SUCCESS, false );
212216
217+ for (smallsizeclass_t sc = 0 ; sc < (MAX_SMALL_SIZECLASS_BITS + 4 ); sc++)
218+ {
219+ const size_t size = bits::one_at_bit (sc);
220+ printf (" malloc_conceal: %zu\n " , size);
221+ errno = SUCCESS;
222+ check_result (size, 1 , our_malloc_conceal (size), SUCCESS, false );
223+ errno = SUCCESS;
224+ check_result (size + 1 , 1 , our_malloc_conceal (size + 1 ), SUCCESS, false );
225+ }
226+
227+ for (smallsizeclass_t sc = 0 ; sc < NUM_SMALL_SIZECLASSES; sc++)
228+ {
229+ const size_t size = sizeclass_to_size (sc);
230+
231+ bool overflow = false ;
232+ for (size_t n = 1 ;
233+ bits::umul (size, n, overflow) <= MAX_SMALL_SIZECLASS_SIZE;
234+ n *= 5 )
235+ {
236+ if (overflow)
237+ break ;
238+
239+ test_calloc (our_calloc_conceal, n, size, SUCCESS, false );
240+ test_calloc (our_calloc_conceal, n, 0 , SUCCESS, false );
241+ }
242+ test_calloc (our_calloc_conceal, 0 , size, SUCCESS, false );
243+ }
244+
213245 test_posix_memalign (0 , 0 , EINVAL, true );
214246 test_posix_memalign (((size_t )-1 ) / 2 , 0 , EINVAL, true );
215247 test_posix_memalign (OS_PAGE_SIZE, sizeof (uintptr_t ) / 2 , EINVAL, true );
0 commit comments