Skip to content

Commit 68fea95

Browse files
authored
Merge branch 'main' into CI-CD-Updates
2 parents 4edc2f5 + d6bccb1 commit 68fea95

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

portable/MemMang/heap_4.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,19 @@ void * pvPortCalloc( size_t xNum,
444444
static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
445445
{
446446
BlockLink_t * pxFirstFreeBlock;
447-
uint8_t * pucAlignedHeap;
448-
portPOINTER_SIZE_TYPE uxAddress;
447+
portPOINTER_SIZE_TYPE uxStartAddress, uxEndAddress;
449448
size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
450449

451450
/* Ensure the heap starts on a correctly aligned boundary. */
452-
uxAddress = ( portPOINTER_SIZE_TYPE ) ucHeap;
451+
uxStartAddress = ( portPOINTER_SIZE_TYPE ) ucHeap;
453452

454-
if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
453+
if( ( uxStartAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
455454
{
456-
uxAddress += ( portBYTE_ALIGNMENT - 1 );
457-
uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
458-
xTotalHeapSize -= ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) ucHeap );
455+
uxStartAddress += ( portBYTE_ALIGNMENT - 1 );
456+
uxStartAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
457+
xTotalHeapSize -= ( size_t ) ( uxStartAddress - ( portPOINTER_SIZE_TYPE ) ucHeap );
459458
}
460459

461-
pucAlignedHeap = ( uint8_t * ) uxAddress;
462-
463460
#if ( configENABLE_HEAP_PROTECTOR == 1 )
464461
{
465462
vApplicationGetRandomHeapCanary( &( xHeapCanary ) );
@@ -468,22 +465,22 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
468465

469466
/* xStart is used to hold a pointer to the first item in the list of free
470467
* blocks. The void cast is used to prevent compiler warnings. */
471-
xStart.pxNextFreeBlock = ( void * ) heapPROTECT_BLOCK_POINTER( pucAlignedHeap );
468+
xStart.pxNextFreeBlock = ( void * ) heapPROTECT_BLOCK_POINTER( uxStartAddress );
472469
xStart.xBlockSize = ( size_t ) 0;
473470

474471
/* pxEnd is used to mark the end of the list of free blocks and is inserted
475472
* at the end of the heap space. */
476-
uxAddress = ( portPOINTER_SIZE_TYPE ) ( pucAlignedHeap + xTotalHeapSize );
477-
uxAddress -= ( portPOINTER_SIZE_TYPE ) xHeapStructSize;
478-
uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
479-
pxEnd = ( BlockLink_t * ) uxAddress;
473+
uxEndAddress = uxStartAddress + ( portPOINTER_SIZE_TYPE ) xTotalHeapSize;
474+
uxEndAddress -= ( portPOINTER_SIZE_TYPE ) xHeapStructSize;
475+
uxEndAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
476+
pxEnd = ( BlockLink_t * ) uxEndAddress;
480477
pxEnd->xBlockSize = 0;
481478
pxEnd->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL );
482479

483480
/* To start with there is a single free block that is sized to take up the
484481
* entire heap space, minus the space taken by pxEnd. */
485-
pxFirstFreeBlock = ( BlockLink_t * ) pucAlignedHeap;
486-
pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
482+
pxFirstFreeBlock = ( BlockLink_t * ) uxStartAddress;
483+
pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxEndAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
487484
pxFirstFreeBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( pxEnd );
488485

489486
/* Only one block exists - and it covers the entire usable heap space. */

portable/MemMang/heap_5.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@
138138

139139
#else /* if ( configENABLE_HEAP_PROTECTOR == 1 ) */
140140

141-
#define heapPROTECT_BLOCK_POINTER( pxBlock ) ( pxBlock )
141+
#define heapPROTECT_BLOCK_POINTER( pxBlock ) ( pxBlock )
142142

143-
#define heapVALIDATE_BLOCK_POINTER( pxBlock ) ( pxBlock )
143+
#define heapVALIDATE_BLOCK_POINTER( pxBlock )
144144

145145
#endif /* configENABLE_HEAP_PROTECTOR */
146146

@@ -562,7 +562,7 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) /* PRIVI
562562
if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
563563
{
564564
xAddress += ( portBYTE_ALIGNMENT - 1 );
565-
xAddress &= ~portBYTE_ALIGNMENT_MASK;
565+
xAddress &= ~( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK;
566566

567567
/* Adjust the size for the bytes lost to alignment. */
568568
xTotalRegionSize -= ( size_t ) ( xAddress - ( portPOINTER_SIZE_TYPE ) pxHeapRegion->pucStartAddress );

0 commit comments

Comments
 (0)