[Fix] Type for pointers operations (#550)

* fix type for pointers operations in some places: size_t -> portPOINTER_SIZE_TYPE

* fix pointer arithmetics

* fix xAddress type
This commit is contained in:
Octaviarius 2022-08-30 23:27:39 +03:00 committed by GitHub
parent ac69aa858a
commit dc8f8be53e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View File

@ -353,7 +353,7 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
/* To start with there is a single free block that is sized to take up the /* To start with there is a single free block that is sized to take up the
* entire heap space. */ * entire heap space. */
pxFirstFreeBlock = ( void * ) pucAlignedHeap; pxFirstFreeBlock = ( BlockLink_t * ) pucAlignedHeap;
pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE; pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE;
pxFirstFreeBlock->pxNextFreeBlock = &xEnd; pxFirstFreeBlock->pxNextFreeBlock = &xEnd;
} }

View File

@ -377,17 +377,17 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
{ {
BlockLink_t * pxFirstFreeBlock; BlockLink_t * pxFirstFreeBlock;
uint8_t * pucAlignedHeap; uint8_t * pucAlignedHeap;
size_t uxAddress; portPOINTER_SIZE_TYPE uxAddress;
size_t xTotalHeapSize = configTOTAL_HEAP_SIZE; size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
/* Ensure the heap starts on a correctly aligned boundary. */ /* Ensure the heap starts on a correctly aligned boundary. */
uxAddress = ( size_t ) ucHeap; uxAddress = ( portPOINTER_SIZE_TYPE ) ucHeap;
if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
{ {
uxAddress += ( portBYTE_ALIGNMENT - 1 ); uxAddress += ( portBYTE_ALIGNMENT - 1 );
uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
xTotalHeapSize -= uxAddress - ( size_t ) ucHeap; xTotalHeapSize -= uxAddress - ( portPOINTER_SIZE_TYPE ) ucHeap;
} }
pucAlignedHeap = ( uint8_t * ) uxAddress; pucAlignedHeap = ( uint8_t * ) uxAddress;
@ -399,17 +399,17 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
/* pxEnd is used to mark the end of the list of free blocks and is inserted /* pxEnd is used to mark the end of the list of free blocks and is inserted
* at the end of the heap space. */ * at the end of the heap space. */
uxAddress = ( ( size_t ) pucAlignedHeap ) + xTotalHeapSize; uxAddress = ( ( portPOINTER_SIZE_TYPE ) pucAlignedHeap ) + xTotalHeapSize;
uxAddress -= xHeapStructSize; uxAddress -= xHeapStructSize;
uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
pxEnd = ( void * ) uxAddress; pxEnd = ( BlockLink_t * ) uxAddress;
pxEnd->xBlockSize = 0; pxEnd->xBlockSize = 0;
pxEnd->pxNextFreeBlock = NULL; pxEnd->pxNextFreeBlock = NULL;
/* To start with there is a single free block that is sized to take up the /* To start with there is a single free block that is sized to take up the
* entire heap space, minus the space taken by pxEnd. */ * entire heap space, minus the space taken by pxEnd. */
pxFirstFreeBlock = ( void * ) pucAlignedHeap; pxFirstFreeBlock = ( BlockLink_t * ) pucAlignedHeap;
pxFirstFreeBlock->xBlockSize = uxAddress - ( size_t ) pxFirstFreeBlock; pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
pxFirstFreeBlock->pxNextFreeBlock = pxEnd; pxFirstFreeBlock->pxNextFreeBlock = pxEnd;
/* Only one block exists - and it covers the entire usable heap space. */ /* Only one block exists - and it covers the entire usable heap space. */

View File

@ -442,10 +442,10 @@ static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert )
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
{ {
BlockLink_t * pxFirstFreeBlockInRegion = NULL, * pxPreviousFreeBlock; BlockLink_t * pxFirstFreeBlockInRegion = NULL, * pxPreviousFreeBlock;
size_t xAlignedHeap; portPOINTER_SIZE_TYPE xAlignedHeap;
size_t xTotalRegionSize, xTotalHeapSize = 0; size_t xTotalRegionSize, xTotalHeapSize = 0;
BaseType_t xDefinedRegions = 0; BaseType_t xDefinedRegions = 0;
size_t xAddress; portPOINTER_SIZE_TYPE xAddress;
const HeapRegion_t * pxHeapRegion; const HeapRegion_t * pxHeapRegion;
/* Can only call once! */ /* Can only call once! */
@ -458,7 +458,7 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
xTotalRegionSize = pxHeapRegion->xSizeInBytes; xTotalRegionSize = pxHeapRegion->xSizeInBytes;
/* Ensure the heap region starts on a correctly aligned boundary. */ /* Ensure the heap region starts on a correctly aligned boundary. */
xAddress = ( size_t ) pxHeapRegion->pucStartAddress; xAddress = ( portPOINTER_SIZE_TYPE ) pxHeapRegion->pucStartAddress;
if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
{ {
@ -466,7 +466,7 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
xAddress &= ~portBYTE_ALIGNMENT_MASK; xAddress &= ~portBYTE_ALIGNMENT_MASK;
/* Adjust the size for the bytes lost to alignment. */ /* Adjust the size for the bytes lost to alignment. */
xTotalRegionSize -= xAddress - ( size_t ) pxHeapRegion->pucStartAddress; xTotalRegionSize -= ( size_t ) ( xAddress - ( portPOINTER_SIZE_TYPE ) pxHeapRegion->pucStartAddress );
} }
xAlignedHeap = xAddress; xAlignedHeap = xAddress;
@ -506,7 +506,7 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
* sized to take up the entire heap region minus the space taken by the * sized to take up the entire heap region minus the space taken by the
* free block structure. */ * free block structure. */
pxFirstFreeBlockInRegion = ( BlockLink_t * ) xAlignedHeap; pxFirstFreeBlockInRegion = ( BlockLink_t * ) xAlignedHeap;
pxFirstFreeBlockInRegion->xBlockSize = xAddress - ( size_t ) pxFirstFreeBlockInRegion; pxFirstFreeBlockInRegion->xBlockSize = ( size_t ) ( xAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlockInRegion );
pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd; pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd;
/* If this is not the first region that makes up the entire heap space /* If this is not the first region that makes up the entire heap space