From 0241f5654c3ef17cdb5db80ea3ab975d52c827e4 Mon Sep 17 00:00:00 2001 From: Stefan Tauner Date: Fri, 18 Mar 2022 03:51:43 +0100 Subject: [PATCH 1/3] freelist: fix typo --- src/malloc_freelist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From cae194a79cc918f95f27d8beb328667810e4c34c Mon Sep 17 00:00:00 2001 From: Stefan Tauner Date: Tue, 29 Mar 2022 12:35:40 +0200 Subject: [PATCH 2/3] freelist: use size_t instead of int for indices --- test/src/malloc_freelist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/src/malloc_freelist.c b/test/src/malloc_freelist.c index bd90ac8..7f08836 100644 --- a/test/src/malloc_freelist.c +++ b/test/src/malloc_freelist.c @@ -45,7 +45,7 @@ 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]); @@ -53,13 +53,13 @@ static void malloc_test(void** __attribute__((unused)) state) } // 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]); @@ -67,7 +67,7 @@ static void malloc_test(void** __attribute__((unused)) state) } // Cleanup - for(int i = 0; i < ALLOCATION_TEST_COUNT; i++) + for(size_t i = 0; i < ALLOCATION_TEST_COUNT; i++) { free(p[i]); } From 4d8e7176d9b103fb621abaddcd9da0481dcd97c1 Mon Sep 17 00:00:00 2001 From: Stefan Tauner Date: Tue, 29 Mar 2022 12:34:23 +0200 Subject: [PATCH 3/3] freelist: test for unique addresses returned by malloc --- test/src/malloc_freelist.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/src/malloc_freelist.c b/test/src/malloc_freelist.c index 7f08836..7864c85 100644 --- a/test/src/malloc_freelist.c +++ b/test/src/malloc_freelist.c @@ -50,6 +50,9 @@ static void malloc_test(void** __attribute__((unused)) state) 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 @@ -64,6 +67,8 @@ static void malloc_test(void** __attribute__((unused)) state) 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