From 1fb4e847ed48963e0043dc4e9dcf3540d7797e44 Mon Sep 17 00:00:00 2001 From: Qikai Date: Tue, 5 Oct 2021 02:15:00 +0800 Subject: [PATCH] Fix the defect that Heap_1.c may waste first portBYTE_ALIGNMENT bytes of ucHeap[] (#238) * Fix the defect that Heap_1.c may waste first 8 bytes of ucHeap[] * Fix the same byte waste issue in heap_2 --- portable/MemMang/heap_1.c | 2 +- portable/MemMang/heap_2.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/portable/MemMang/heap_1.c b/portable/MemMang/heap_1.c index 68c4c5f77..e17cdc7f6 100644 --- a/portable/MemMang/heap_1.c +++ b/portable/MemMang/heap_1.c @@ -96,7 +96,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. */ diff --git a/portable/MemMang/heap_2.c b/portable/MemMang/heap_2.c index b16b24564..afa00df3c 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. */