diff --git a/src/malloc_freelist.c b/src/malloc_freelist.c index a74a678..e79136c 100644 --- a/src/malloc_freelist.c +++ b/src/malloc_freelist.c @@ -20,7 +20,7 @@ /* * This is the container for our free-list. - * Node the usage of the linked list here: the library uses offsetof + * Note the usage of the linked list here: the library uses offsetof * and container_of to manage the list and get back to the parent struct. */ typedef struct diff --git a/test/src/malloc_freelist.c b/test/src/malloc_freelist.c index bd90ac8..7864c85 100644 --- a/test/src/malloc_freelist.c +++ b/test/src/malloc_freelist.c @@ -45,29 +45,34 @@ static void malloc_test(void** __attribute__((unused)) state) ptr = malloc(2 * mem_block_size); assert_null(ptr); - for(int i = 0; i < ALLOCATION_TEST_COUNT; i++) + for(size_t i = 0; i < ALLOCATION_TEST_COUNT; i++) { p[i] = malloc(1024); assert_non_null(p[i]); assert_in_range((uintptr_t)p[i], mem_block_addr, mem_block_end_addr); + // Test for unique addresses + if(i > 0) + assert_not_in_set((uintptr_t)p[i], (uintptr_t*)p, i - 1); } // Cleanup - for(int i = 0; i < ALLOCATION_TEST_COUNT; i++) + for(size_t i = 0; i < ALLOCATION_TEST_COUNT; i++) { free(p[i]); } // Run test again, will not fail if our memory has been returned! - for(int i = 0; i < ALLOCATION_TEST_COUNT; i++) + for(size_t i = 0; i < ALLOCATION_TEST_COUNT; i++) { p[i] = malloc(1024); assert_non_null(p[i]); assert_in_range((uintptr_t)p[i], mem_block_addr, mem_block_end_addr); + if(i > 0) + assert_not_in_set((uintptr_t)p[i], (uintptr_t*)p, i - 1); } // Cleanup - for(int i = 0; i < ALLOCATION_TEST_COUNT; i++) + for(size_t i = 0; i < ALLOCATION_TEST_COUNT; i++) { free(p[i]); }