adjustments for consistency

This commit is contained in:
Cobus van Eeden 2020-12-05 16:14:04 -08:00
parent 8aa5f3bba2
commit 3c56f1186a
2 changed files with 38 additions and 44 deletions

View file

@ -134,26 +134,28 @@ void * pvPortMalloc( size_t xWantedSize )
/* The wanted size must be increased so it can contain a BlockLink_t /* The wanted size must be increased so it can contain a BlockLink_t
* structure in addition to the requested amount of bytes. */ * structure in addition to the requested amount of bytes. */
if( xWantedSize > 0 ) if( ( xWantedSize > 0 ) &&
( ( xWantedSize + xHeapStructSize ) > xWantedSize ) ) /* Overflow check */
{ {
/* Ensure xWantedSize will never wrap after adjustment, even if we need xWantedSize += heapSTRUCT_SIZE;
* an alignment adjustment */
if( ( xWantedSize > 0 ) && ( ( xWantedSize + xHeapStructSize ) > xWantedSize ) )
{
xWantedSize += heapSTRUCT_SIZE;
/* Ensure that blocks are always aligned to the required number of bytes. */ /* Byte alignment required. (check for overflow again) */
if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0 ) if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) )
{ > xWantedSize )
/* Byte alignment required. */ {
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
} configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );
} else {
/* If the requested size is too large to handle we force an error */
xWantedSize = 0;
} }
else
{
xWantedSize = 0;
}
} else {
/* If the requested size is too large to handle we force an error */
xWantedSize = 0;
} }
if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
{ {
/* Blocks are stored in byte order - traverse the list from the start /* Blocks are stored in byte order - traverse the list from the start

View file

@ -136,44 +136,36 @@ void * pvPortMalloc( size_t xWantedSize )
* kernel, so it must be free. */ * kernel, so it must be free. */
if( ( xWantedSize & xBlockAllocatedBit ) == 0 ) if( ( xWantedSize & xBlockAllocatedBit ) == 0 )
{ {
/* The wanted size is increased so it can contain a BlockLink_t /* The wanted size must be increased so it can contain a BlockLink_t
* structure in addition to the requested amount of bytes. */ * structure in addition to the requested amount of bytes. */
if( xWantedSize > 0 ) if( ( xWantedSize > 0 ) &&
( ( xWantedSize + xHeapStructSize ) > xWantedSize ) ) /* Overflow check */
{ {
/* Check for overflow */ xWantedSize += xHeapStructSize;
if ( ( xWantedSize + xHeapStructSize ) > xWantedSize )
{
xWantedSize += xHeapStructSize;
/* Ensure that blocks are always aligned to the required number /* Ensure that blocks are always aligned */
* of bytes. */ if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 )
if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 ) {
/* Byte alignment required. (check for overflow again) */
if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) )
> xWantedSize )
{ {
/* Byte alignment required. (check for overflow again) */ xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) ) configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );
> xWantedSize )
{
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );
}
else
{
xWantedSize = 0;
}
} }
else else
{ {
mtCOVERAGE_TEST_MARKER(); xWantedSize = 0;
} }
}
else
{
xWantedSize = 0;
} }
} else
else {
mtCOVERAGE_TEST_MARKER();
}
}
else
{ {
mtCOVERAGE_TEST_MARKER(); xWantedSize = 0;
} }
if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )