Skip to content

Commit 1fb4e84

Browse files
authored
Fix the defect that Heap_1.c may waste first portBYTE_ALIGNMENT bytes of ucHeap[] (FreeRTOS#238)
* Fix the defect that Heap_1.c may waste first 8 bytes of ucHeap[] * Fix the same byte waste issue in heap_2
1 parent 5f290e4 commit 1fb4e84

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

portable/MemMang/heap_1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void * pvPortMalloc( size_t xWantedSize )
9696
if( pucAlignedHeap == NULL )
9797
{
9898
/* Ensure the heap starts on a correctly aligned boundary. */
99-
pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
99+
pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
100100
}
101101

102102
/* Check there is enough room left for the allocation and. */

portable/MemMang/heap_2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static void prvHeapInit( void )
266266
uint8_t * pucAlignedHeap;
267267

268268
/* Ensure the heap starts on a correctly aligned boundary. */
269-
pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
269+
pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
270270

271271
/* xStart is used to hold a pointer to the first item in the list of free
272272
* blocks. The void cast is used to prevent compiler warnings. */

0 commit comments

Comments
 (0)