mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-10 08:07:46 -04:00
Readability improvements
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
parent
4c04d2485a
commit
24a20e20b3
1 changed files with 29 additions and 7 deletions
|
@ -53,6 +53,14 @@
|
|||
/* A few bytes might be lost to byte aligning the heap start address. */
|
||||
#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT )
|
||||
|
||||
/* Max value that fits in a size_t type. */
|
||||
#define heapSIZE_MAX ( ~( ( size_t ) 0 ) )
|
||||
|
||||
/* Check if adding a and b will result in overflow. */
|
||||
#define heapADD_WILL_OVERFLOW( a, b ) ( ( a ) > ( heapSIZE_MAX - ( b ) ) )
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Allocate the memory for the heap. */
|
||||
#if ( configAPPLICATION_ALLOCATED_HEAP == 1 )
|
||||
|
||||
|
@ -76,9 +84,21 @@ void * pvPortMalloc( size_t xWantedSize )
|
|||
/* Ensure that blocks are always aligned. */
|
||||
#if ( portBYTE_ALIGNMENT != 1 )
|
||||
{
|
||||
if( xWantedSize & portBYTE_ALIGNMENT_MASK )
|
||||
size_t xAdditionalRequiredSize;
|
||||
|
||||
if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 )
|
||||
{
|
||||
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
|
||||
/* Byte alignment required. */
|
||||
xAdditionalRequiredSize = portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK );
|
||||
|
||||
if( heapADD_WILL_OVERFLOW( xWantedSize, xAdditionalRequiredSize ) == 0 )
|
||||
{
|
||||
xWantedSize += xAdditionalRequiredSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
xWantedSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* if ( portBYTE_ALIGNMENT != 1 ) */
|
||||
|
@ -88,12 +108,14 @@ void * pvPortMalloc( size_t xWantedSize )
|
|||
if( pucAlignedHeap == NULL )
|
||||
{
|
||||
/* Ensure the heap starts on a correctly aligned boundary. */
|
||||
pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
|
||||
pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) &( ucHeap[ portBYTE_ALIGNMENT - 1 ] ) ) &
|
||||
( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
|
||||
}
|
||||
|
||||
/* Check there is enough room left for the allocation and. */
|
||||
if( ( xWantedSize > 0 ) && /* valid size */
|
||||
( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE )) /* check for overflow */
|
||||
/* Check there is enough room left for the allocation. */
|
||||
if( ( xWantedSize > 0 ) &&
|
||||
( heapADD_WILL_OVERFLOW( xNextFreeByte, xWantedSize ) == 0 ) &&
|
||||
( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) )
|
||||
{
|
||||
/* Return the next free byte then increment the index past this
|
||||
* block. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue