@@ -87,11 +87,20 @@ 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 (
91
+ void *(*calloc_fn)(size_t , size_t ),
92
+ size_t nmemb,
93
+ size_t size,
94
+ int err,
95
+ bool null)
91
96
{
92
- printf (" calloc(%zu, %zu) combined size %zu\n " , nmemb, size, nmemb * size);
97
+ printf (" calloc" );
98
+ if (calloc_fn == our_calloc_conceal)
99
+ printf (" _conceal" );
100
+
101
+ printf (" (%zu, %zu) combined size %zu\n " , nmemb, size, nmemb * size);
93
102
errno = SUCCESS;
94
- void * p = our_calloc (nmemb, size);
103
+ void * p = calloc_fn (nmemb, size);
95
104
96
105
if (p != nullptr )
97
106
{
@@ -157,7 +166,7 @@ int main(int argc, char** argv)
157
166
check_result (size + 1 , 1 , our_malloc (size + 1 ), SUCCESS, false );
158
167
}
159
168
160
- test_calloc (0 , 0 , SUCCESS, false );
169
+ test_calloc (our_calloc, 0 , 0 , SUCCESS, false );
161
170
162
171
our_free (nullptr );
163
172
@@ -173,10 +182,10 @@ int main(int argc, char** argv)
173
182
if (overflow)
174
183
break ;
175
184
176
- test_calloc (n, size, SUCCESS, false );
177
- test_calloc (n, 0 , SUCCESS, false );
185
+ test_calloc (our_calloc, n, size, SUCCESS, false );
186
+ test_calloc (our_calloc, n, 0 , SUCCESS, false );
178
187
}
179
- test_calloc (0 , size, SUCCESS, false );
188
+ test_calloc (our_calloc, 0 , size, SUCCESS, false );
180
189
}
181
190
182
191
for (smallsizeclass_t sc = 0 ; sc < NUM_SMALL_SIZECLASSES; sc++)
@@ -210,6 +219,34 @@ int main(int argc, char** argv)
210
219
211
220
test_realloc (our_malloc (64 ), 4194304 , SUCCESS, false );
212
221
222
+ for (smallsizeclass_t sc = 0 ; sc < (MAX_SMALL_SIZECLASS_BITS + 4 ); sc++)
223
+ {
224
+ const size_t size = bits::one_at_bit (sc);
225
+ printf (" malloc_conceal: %zu\n " , size);
226
+ errno = SUCCESS;
227
+ check_result (size, 1 , our_malloc_conceal (size), SUCCESS, false );
228
+ errno = SUCCESS;
229
+ check_result (size + 1 , 1 , our_malloc_conceal (size + 1 ), SUCCESS, false );
230
+ }
231
+
232
+ for (smallsizeclass_t sc = 0 ; sc < NUM_SMALL_SIZECLASSES; sc++)
233
+ {
234
+ const size_t size = sizeclass_to_size (sc);
235
+
236
+ bool overflow = false ;
237
+ for (size_t n = 1 ;
238
+ bits::umul (size, n, overflow) <= MAX_SMALL_SIZECLASS_SIZE;
239
+ n *= 5 )
240
+ {
241
+ if (overflow)
242
+ break ;
243
+
244
+ test_calloc (our_calloc_conceal, n, size, SUCCESS, false );
245
+ test_calloc (our_calloc_conceal, n, 0 , SUCCESS, false );
246
+ }
247
+ test_calloc (our_calloc_conceal, 0 , size, SUCCESS, false );
248
+ }
249
+
213
250
test_posix_memalign (0 , 0 , EINVAL, true );
214
251
test_posix_memalign (((size_t )-1 ) / 2 , 0 , EINVAL, true );
215
252
test_posix_memalign (OS_PAGE_SIZE, sizeof (uintptr_t ) / 2 , EINVAL, true );
0 commit comments