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,25 +134,27 @@ 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
* an alignment adjustment */
if( ( xWantedSize > 0 ) && ( ( xWantedSize + xHeapStructSize ) > xWantedSize ) )
{ {
xWantedSize += heapSTRUCT_SIZE; 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
{
xWantedSize = 0;
} }
} else { } else {
/* If the requested size is too large to handle we force an error */ /* If the requested size is too large to handle we force an error */
xWantedSize = 0; xWantedSize = 0;
} }
}
if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
{ {

View file

@ -136,17 +136,14 @@ 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 */
if ( ( xWantedSize + xHeapStructSize ) > xWantedSize )
{ {
xWantedSize += xHeapStructSize; 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) */ /* Byte alignment required. (check for overflow again) */
@ -170,11 +167,6 @@ void * pvPortMalloc( size_t xWantedSize )
{ {
xWantedSize = 0; xWantedSize = 0;
} }
}
else
{
mtCOVERAGE_TEST_MARKER();
}
if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
{ {