@@ -87,11 +87,15 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
87
87
our_free (p);
88
88
}
89
89
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)
91
91
{
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);
93
97
errno = SUCCESS;
94
- void * p = our_calloc (nmemb, size);
98
+ void * p = calloc_fn (nmemb, size);
95
99
96
100
if (p != nullptr )
97
101
{
@@ -157,7 +161,7 @@ int main(int argc, char** argv)
157
161
check_result (size + 1 , 1 , our_malloc (size + 1 ), SUCCESS, false );
158
162
}
159
163
160
- test_calloc (0 , 0 , SUCCESS, false );
164
+ test_calloc (our_calloc, 0 , 0 , SUCCESS, false );
161
165
162
166
our_free (nullptr );
163
167
@@ -173,10 +177,10 @@ int main(int argc, char** argv)
173
177
if (overflow)
174
178
break ;
175
179
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 );
178
182
}
179
- test_calloc (0 , size, SUCCESS, false );
183
+ test_calloc (our_calloc, 0 , size, SUCCESS, false );
180
184
}
181
185
182
186
for (smallsizeclass_t sc = 0 ; sc < NUM_SMALL_SIZECLASSES; sc++)
@@ -210,6 +214,34 @@ int main(int argc, char** argv)
210
214
211
215
test_realloc (our_malloc (64 ), 4194304 , SUCCESS, false );
212
216
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
+
213
245
test_posix_memalign (0 , 0 , EINVAL, true );
214
246
test_posix_memalign (((size_t )-1 ) / 2 , 0 , EINVAL, true );
215
247
test_posix_memalign (OS_PAGE_SIZE, sizeof (uintptr_t ) / 2 , EINVAL, true );
0 commit comments