Skip to content

Commit 231278e

Browse files
kar-rahul-awsSkptakchinglee-iot
authored
Fix cast alignment warning in heap_4.c and heap_5.c (#771)
* Fix cast alignment warning --------- Co-authored-by: Soren Ptak <[email protected]> Co-authored-by: chinglee-iot <[email protected]>
1 parent 1aaa318 commit 231278e

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

portable/MemMang/heap_4.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ void * pvPortCalloc( size_t xNum,
444444
static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
445445
{
446446
BlockLink_t * pxFirstFreeBlock;
447-
uint8_t * pucAlignedHeap;
448447
portPOINTER_SIZE_TYPE uxAddress;
449448
size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
450449

@@ -458,8 +457,6 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
458457
xTotalHeapSize -= ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) ucHeap );
459458
}
460459

461-
pucAlignedHeap = ( uint8_t * ) uxAddress;
462-
463460
#if ( configENABLE_HEAP_PROTECTOR == 1 )
464461
{
465462
vApplicationGetRandomHeapCanary( &( xHeapCanary ) );
@@ -468,12 +465,12 @@ 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( uxAddress );
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 );
473+
uxAddress = ( portPOINTER_SIZE_TYPE ) ( uxAddress + xTotalHeapSize );
477474
uxAddress -= ( portPOINTER_SIZE_TYPE ) xHeapStructSize;
478475
uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
479476
pxEnd = ( BlockLink_t * ) uxAddress;
@@ -482,7 +479,7 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
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;
482+
pxFirstFreeBlock = ( BlockLink_t * ) uxAddress;
486483
pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
487484
pxFirstFreeBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( pxEnd );
488485

portable/MemMang/heap_5.c

+3-3
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)