@@ -444,22 +444,19 @@ void * pvPortCalloc( size_t xNum,
444444static 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. */
0 commit comments