Skip to content

Commit dc8f8be

Browse files
authored
[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
1 parent ac69aa8 commit dc8f8be

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

portable/MemMang/heap_2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
353353

354354
/* To start with there is a single free block that is sized to take up the
355355
* entire heap space. */
356-
pxFirstFreeBlock = ( void * ) pucAlignedHeap;
356+
pxFirstFreeBlock = ( BlockLink_t * ) pucAlignedHeap;
357357
pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE;
358358
pxFirstFreeBlock->pxNextFreeBlock = &xEnd;
359359
}

portable/MemMang/heap_4.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,17 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
377377
{
378378
BlockLink_t * pxFirstFreeBlock;
379379
uint8_t * pucAlignedHeap;
380-
size_t uxAddress;
380+
portPOINTER_SIZE_TYPE uxAddress;
381381
size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
382382

383383
/* Ensure the heap starts on a correctly aligned boundary. */
384-
uxAddress = ( size_t ) ucHeap;
384+
uxAddress = ( portPOINTER_SIZE_TYPE ) ucHeap;
385385

386386
if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
387387
{
388388
uxAddress += ( portBYTE_ALIGNMENT - 1 );
389-
uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
390-
xTotalHeapSize -= uxAddress - ( size_t ) ucHeap;
389+
uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
390+
xTotalHeapSize -= uxAddress - ( portPOINTER_SIZE_TYPE ) ucHeap;
391391
}
392392

393393
pucAlignedHeap = ( uint8_t * ) uxAddress;
@@ -399,17 +399,17 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
399399

400400
/* pxEnd is used to mark the end of the list of free blocks and is inserted
401401
* at the end of the heap space. */
402-
uxAddress = ( ( size_t ) pucAlignedHeap ) + xTotalHeapSize;
402+
uxAddress = ( ( portPOINTER_SIZE_TYPE ) pucAlignedHeap ) + xTotalHeapSize;
403403
uxAddress -= xHeapStructSize;
404-
uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
405-
pxEnd = ( void * ) uxAddress;
404+
uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
405+
pxEnd = ( BlockLink_t * ) uxAddress;
406406
pxEnd->xBlockSize = 0;
407407
pxEnd->pxNextFreeBlock = NULL;
408408

409409
/* To start with there is a single free block that is sized to take up the
410410
* entire heap space, minus the space taken by pxEnd. */
411-
pxFirstFreeBlock = ( void * ) pucAlignedHeap;
412-
pxFirstFreeBlock->xBlockSize = uxAddress - ( size_t ) pxFirstFreeBlock;
411+
pxFirstFreeBlock = ( BlockLink_t * ) pucAlignedHeap;
412+
pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
413413
pxFirstFreeBlock->pxNextFreeBlock = pxEnd;
414414

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

portable/MemMang/heap_5.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,10 @@ static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert )
442442
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
443443
{
444444
BlockLink_t * pxFirstFreeBlockInRegion = NULL, * pxPreviousFreeBlock;
445-
size_t xAlignedHeap;
445+
portPOINTER_SIZE_TYPE xAlignedHeap;
446446
size_t xTotalRegionSize, xTotalHeapSize = 0;
447447
BaseType_t xDefinedRegions = 0;
448-
size_t xAddress;
448+
portPOINTER_SIZE_TYPE xAddress;
449449
const HeapRegion_t * pxHeapRegion;
450450

451451
/* Can only call once! */
@@ -458,15 +458,15 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
458458
xTotalRegionSize = pxHeapRegion->xSizeInBytes;
459459

460460
/* Ensure the heap region starts on a correctly aligned boundary. */
461-
xAddress = ( size_t ) pxHeapRegion->pucStartAddress;
461+
xAddress = ( portPOINTER_SIZE_TYPE ) pxHeapRegion->pucStartAddress;
462462

463463
if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
464464
{
465465
xAddress += ( portBYTE_ALIGNMENT - 1 );
466466
xAddress &= ~portBYTE_ALIGNMENT_MASK;
467467

468468
/* Adjust the size for the bytes lost to alignment. */
469-
xTotalRegionSize -= xAddress - ( size_t ) pxHeapRegion->pucStartAddress;
469+
xTotalRegionSize -= ( size_t ) ( xAddress - ( portPOINTER_SIZE_TYPE ) pxHeapRegion->pucStartAddress );
470470
}
471471

472472
xAlignedHeap = xAddress;
@@ -506,7 +506,7 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
506506
* sized to take up the entire heap region minus the space taken by the
507507
* free block structure. */
508508
pxFirstFreeBlockInRegion = ( BlockLink_t * ) xAlignedHeap;
509-
pxFirstFreeBlockInRegion->xBlockSize = xAddress - ( size_t ) pxFirstFreeBlockInRegion;
509+
pxFirstFreeBlockInRegion->xBlockSize = ( size_t ) ( xAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlockInRegion );
510510
pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd;
511511

512512
/* If this is not the first region that makes up the entire heap space

0 commit comments

Comments
 (0)