From 280eb768f2346fe236dabfe456d80b19c19d8995 Mon Sep 17 00:00:00 2001 From: QiKai Date: Mon, 21 Dec 2020 17:23:09 +0800 Subject: [PATCH 1/2] Fix the defect that Heap_1.c may waste first 8 bytes of ucHeap[] --- portable/MemMang/heap_1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portable/MemMang/heap_1.c b/portable/MemMang/heap_1.c index a1e96bdf32..db7f94df7e 100644 --- a/portable/MemMang/heap_1.c +++ b/portable/MemMang/heap_1.c @@ -94,7 +94,7 @@ void * pvPortMalloc( size_t xWantedSize ) if( pucAlignedHeap == NULL ) { /* Ensure the heap starts on a correctly aligned boundary. */ - pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); + pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); } /* Check there is enough room left for the allocation and. */ From 2f8d25b0fe62c8107053ad58866ea95d008604db Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Sun, 3 Oct 2021 20:40:31 +0000 Subject: [PATCH 2/2] Fix the same byte waste issue in heap_2 Signed-off-by: Gaurav Aggarwal --- portable/MemMang/heap_2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portable/MemMang/heap_2.c b/portable/MemMang/heap_2.c index b16b24564c..afa00df3c4 100644 --- a/portable/MemMang/heap_2.c +++ b/portable/MemMang/heap_2.c @@ -266,7 +266,7 @@ static void prvHeapInit( void ) uint8_t * pucAlignedHeap; /* Ensure the heap starts on a correctly aligned boundary. */ - pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); + pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); /* xStart is used to hold a pointer to the first item in the list of free * blocks. The void cast is used to prevent compiler warnings. */