Skip to content

Commit

Permalink
Fix MISRA 2012 violations (#1208)
Browse files Browse the repository at this point in the history
* Fix coverity issues

* Fix formatting
  • Loading branch information
tony-josi-aws authored Dec 4, 2024
1 parent 5f41a38 commit e3412fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions source/FreeRTOS_IP_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1717,11 +1717,11 @@ int32_t FreeRTOS_add_int32( int32_t a,
{
int32_t ret;

if( ( a > 0 ) && ( b > ipINT32_MAX_VALUE - a ) )
if( ( a > 0 ) && ( b > ( ipINT32_MAX_VALUE - a ) ) )
{
ret = ipINT32_MAX_VALUE; /* Positive overflow */
}
else if( ( a < 0 ) && ( b < ipINT32_MIN_VALUE - a ) )
else if( ( a < 0 ) && ( b < ( ipINT32_MIN_VALUE - a ) ) )
{
ret = ipINT32_MIN_VALUE; /* Negative underflow */
}
Expand All @@ -1748,11 +1748,11 @@ int32_t FreeRTOS_multiply_int32( int32_t a,
/* Check for overflow/underflow */
if( a > 0 )
{
if( ( b > 0 ) && ( a > ipINT32_MAX_VALUE / b ) )
if( ( b > 0 ) && ( a > ( ipINT32_MAX_VALUE / b ) ) )
{
ret = ipINT32_MAX_VALUE; /* Positive overflow */
}
else if( ( b < 0 ) && ( b < ipINT32_MIN_VALUE / a ) )
else if( ( b < 0 ) && ( b < ( ipINT32_MIN_VALUE / a ) ) )
{
ret = ipINT32_MIN_VALUE; /* Negative underflow */
}
Expand All @@ -1763,11 +1763,11 @@ int32_t FreeRTOS_multiply_int32( int32_t a,
}
else
{
if( ( b > 0 ) && ( a < ipINT32_MIN_VALUE / b ) )
if( ( b > 0 ) && ( a < ( ipINT32_MIN_VALUE / b ) ) )
{
ret = ipINT32_MIN_VALUE; /* Negative underflow */
}
else if( ( b < 0 ) && ( a < ipINT32_MAX_VALUE / b ) )
else if( ( b < 0 ) && ( a < ( ipINT32_MAX_VALUE / b ) ) )
{
ret = ipINT32_MAX_VALUE; /* Positive overflow */
}
Expand Down
3 changes: 3 additions & 0 deletions source/FreeRTOS_ND.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@

/** @brief The time at which the last unsolicited ND was sent. Unsolicited NDs are used
* to ensure ND tables are up to date and to detect IP address conflicts. */
/* MISRA Ref 8.9.1 [File scoped variables] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-89 */
/* coverity[misra_c_2012_rule_8_9_violation] */
static TickType_t xLastUnsolicitedNDTime = 0U;

/*-----------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_TCP_WIN.c
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@
int32_t lWeight = 0;
int32_t lDivisor = 0;

mS = mS < 0 ? ipINT32_MAX_VALUE : mS;
mS = ( mS < 0 ) ? ipINT32_MAX_VALUE : mS;

if( pxWindow->lSRTT >= mS )
{
Expand Down
4 changes: 2 additions & 2 deletions source/include/FreeRTOS_IP.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
#define ipSIZE_OF_TCP_HEADER 20U

/* The maximum of int32 value. */
#define ipINT32_MAX_VALUE ( ( int32_t ) 0x7FFFFFFF )
#define ipINT32_MAX_VALUE ( ( int32_t ) 0x7FFFFFFFU )

/* The minimum of int32 value. */
#define ipINT32_MIN_VALUE ( ( int32_t ) 0x80000000 )
#define ipINT32_MIN_VALUE ( ( int32_t ) 0x80000000U )

/*
* Generate a randomized TCP Initial Sequence Number per RFC.
Expand Down

0 comments on commit e3412fb

Please sign in to comment.