File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,33 @@ void *test_calloc(size_t nelem, size_t elsize)
187
187
return alloc (TEST_CALLOC , nelem * elsize );
188
188
}
189
189
190
+ void * test_realloc (void * p , size_t size )
191
+ {
192
+ /* Reference: Malloc tutorial
193
+ * https://danluu.com/malloc-tutorial/
194
+ */
195
+
196
+ if (!p ) {
197
+ return alloc (TEST_MALLOC , size );
198
+ }
199
+
200
+ const block_element_t * b = find_header (p );
201
+ if (b -> payload_size >= size ) {
202
+ return p ;
203
+ }
204
+
205
+ void * new_ptr ;
206
+ new_ptr = alloc (TEST_MALLOC , size );
207
+ if (!new_ptr ) {
208
+ return NULL ;
209
+ }
210
+ memcpy (new_ptr , p , b -> payload_size );
211
+ test_free (p );
212
+
213
+ return new_ptr ;
214
+ }
215
+
216
+
190
217
void test_free (void * p )
191
218
{
192
219
if (noallocate_mode ) {
Original file line number Diff line number Diff line change 12
12
13
13
void * test_malloc (size_t size );
14
14
void * test_calloc (size_t nmemb , size_t size );
15
+ void * test_realloc (void * p , size_t new_size );
15
16
void test_free (void * p );
16
17
char * test_strdup (const char * s );
17
- /* FIXME: provide test_realloc as well */
18
18
19
19
#ifdef INTERNAL
20
20
@@ -56,6 +56,7 @@ void trigger_exception(char *msg);
56
56
/* Tested program use our versions of malloc and free */
57
57
#define malloc test_malloc
58
58
#define calloc test_calloc
59
+ #define realloc test_realloc
59
60
#define free test_free
60
61
61
62
/* Use undef to avoid strdup redefined error */
You can’t perform that action at this time.
0 commit comments