X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fmalloc.c;fp=functions%2Fstdlib%2Fmalloc.c;h=a97730ff501d0433098b5b9841d8f958954284ee;hb=8165a19ca75f1405d8b8255252aa6330d202679e;hp=c767b17d993c3e6dd80c5d5134746d9ff087ab9c;hpb=3213ac4b86f621b7335aea079c3217b3d8bc6f7c;p=pdclib diff --git a/functions/stdlib/malloc.c b/functions/stdlib/malloc.c index c767b17..a97730f 100644 --- a/functions/stdlib/malloc.c +++ b/functions/stdlib/malloc.c @@ -20,6 +20,7 @@ #endif /* TODO: Primitive placeholder. Much room for improvement. */ +/* TODO: Leaves nodes with size < _PDCLIB_MINALLOC, which are never assigned */ /* Keeping pointers to the first and the last element of the free list. */ struct _PDCLIB_headnode_t _PDCLIB_memlist = { NULL, NULL }; @@ -163,7 +164,7 @@ int main( int argc, char * argv[] ) BEGIN_TESTS; #ifndef REGTEST { - void * ptr1, * ptr2, * ptr3, * ptr4, * ptr5, * ptr6, * ptr7, * ptr8; + void * ptr1, * ptr2, * ptr3, * ptr4, * ptr5, * ptr6, * ptr7, * ptr8, * ptr9; char * pages_start = _PDCLIB_allocpages( 0 ); /* allocating 10 byte; expected: 1 page allocation, node split */ TESTCASE( MEMTEST( ptr1, 10 ) ); @@ -213,6 +214,11 @@ int main( int argc, char * argv[] ) free( ptr8 ); TESTCASE( MEMTEST( ptr8, EFFECTIVE + 1 - _PDCLIB_MINALLOC - sizeof( struct _PDCLIB_memnode_t ) ) ); TESTCASE( PAGETEST( 9 ) ); + /* realloc with NULL pointer; expected: no page allocation, no node split */ + ptr9 = realloc( NULL, 4072 ); + TESTCASE( ptr9 != NULL ); + TESTCASE( memset( ptr9, 0, 4072 ) == ptr9 ); + TESTCASE( PAGETEST( 9 ) ); } #endif return TEST_RESULTS;