From 44d83cbbd8e0a0b6b0f9f2fc3d72469742bf3e3b Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Thu, 28 Jul 2022 18:23:40 -0700 Subject: [PATCH 1/3] MISRA violation fix 17.7, 1.2, 8.9 --- source/FreeRTOS_DNS_Cache.c | 6 ++-- source/FreeRTOS_IP_Utils.c | 32 ++++++++++++--------- source/FreeRTOS_Stream_Buffer.c | 2 +- test/Coverity/ConfigFiles/pack_struct_end.h | 3 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/source/FreeRTOS_DNS_Cache.c b/source/FreeRTOS_DNS_Cache.c index 5ceeed70d7..110245c737 100644 --- a/source/FreeRTOS_DNS_Cache.c +++ b/source/FreeRTOS_DNS_Cache.c @@ -173,9 +173,9 @@ { /* Element found */ if( xLookUp == pdTRUE ) { - prvGetCacheIPEntry( uxIndex, - pulIP, - ulCurrentTimeSeconds ); + ( void ) prvGetCacheIPEntry( uxIndex, + pulIP, + ulCurrentTimeSeconds ); } else { diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 35b1d525df..f918ef9175 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -136,7 +136,7 @@ static NetworkBufferDescriptor_t * prvPacketBuffer_to_NetworkBuffer( const void xEventMessage.eEventType = eDHCPEvent; /* MISRA Ref 11.6.1 [DHCP events and conversion to void] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-116 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-116 */ /* coverity[misra_c_2012_rule_11_6_violation] */ xEventMessage.pvData = ( void * ) uxOption; @@ -231,7 +231,7 @@ static NetworkBufferDescriptor_t * prvPacketBuffer_to_NetworkBuffer( const void /* Obtain the network buffer from the zero copy pointer. */ /* MISRA Ref 11.6.2 [Pointer arithmetic and hidden pointer] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-116 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-116 */ /* coverity[misra_c_2012_rule_11_6_violation] */ uxBuffer = ( uintptr_t ) pvBuffer; @@ -245,7 +245,7 @@ static NetworkBufferDescriptor_t * prvPacketBuffer_to_NetworkBuffer( const void if( ( uxBuffer & ( ( ( uintptr_t ) sizeof( uxBuffer ) ) - 1U ) ) == ( uintptr_t ) 0U ) { /* MISRA Ref 11.4.2 [Validation of pointer alignment] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */ /* coverity[misra_c_2012_rule_11_4_violation] */ pxResult = *( ( NetworkBufferDescriptor_t ** ) uxBuffer ); } @@ -321,6 +321,10 @@ BaseType_t xIsCallingFromIPTask( void ) /** * @brief Process a 'Network down' event and complete required processing. */ +/* 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] */ +/* coverity[single_use] */ void prvProcessNetworkDownEvent( void ) { /* Stop the ARP timer while there is no network. */ @@ -473,7 +477,7 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer, /* Parse the packet length. */ /* MISRA Ref 11.3.1 [Misaligned access] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer ); @@ -518,7 +522,7 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer, * of this calculation. */ /* MISRA Ref 11.3.1 [Misaligned access] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtPack = ( ( ProtocolPacket_t * ) &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); @@ -848,7 +852,7 @@ uint16_t usGenerateChecksum( uint16_t usSum, xSource.u8ptr = pucNextData; /* MISRA Ref 11.4.3 [Casting pointer to int for verification] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */ /* coverity[misra_c_2012_rule_11_4_violation] */ uxAlignBits = ( ( ( uintptr_t ) pucNextData ) & 0x03U ); @@ -956,21 +960,23 @@ uint16_t usGenerateChecksum( uint16_t usSum, } /* MISRA Ref 2.2.1 [Unions and dead code] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-22 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-22 */ /* coverity[misra_c_2012_rule_2_2_violation] */ + /* coverity[assigned_value] */ xSum.u32 += xTerm.u32; /* Now add all carries again. */ - /* Assigning value from "xTerm.u32" to "xSum.u32" here, but that stored value is overwritten before it can be used. - * /* MISRA Ref 2.2.1 [Unions and dead code] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-22 */ + /* Assigning value from "xTerm.u32" to "xSum.u32" here, but that stored value is overwritten before it can be used. */ + /* MISRA Ref 2.2.1 [Unions and dead code] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-22 */ /* coverity[misra_c_2012_rule_2_2_violation] */ + /* coverity[value_overwrite] */ xSum.u32 = ( uint32_t ) xSum.u16[ 0 ] + xSum.u16[ 1 ]; /* coverity[value_overwrite] */ /* MISRA Ref 2.2.1 [Unions and dead code] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-22 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-22 */ /* coverity[misra_c_2012_rule_2_2_violation] */ xSum.u32 = ( uint32_t ) xSum.u16[ 0 ] + xSum.u16[ 1 ]; @@ -1149,7 +1155,7 @@ const char * FreeRTOS_strerror_r( BaseType_t xErrnum, default: /* MISRA Ref 21.6.1 [snprintf and logging] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-216 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-216 */ /* coverity[misra_c_2012_rule_21_6_violation] */ ( void ) snprintf( pcBuffer, uxLength, "Errno %d", xErrnum ); pcName = NULL; @@ -1159,7 +1165,7 @@ const char * FreeRTOS_strerror_r( BaseType_t xErrnum, if( pcName != NULL ) { /* MISRA Ref 21.6.1 [snprintf and logging] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-216 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-216 */ /* coverity[misra_c_2012_rule_21_6_violation] */ ( void ) snprintf( pcBuffer, uxLength, "%s", pcName ); } diff --git a/source/FreeRTOS_Stream_Buffer.c b/source/FreeRTOS_Stream_Buffer.c index 97dcaf3db7..26b54352c8 100644 --- a/source/FreeRTOS_Stream_Buffer.c +++ b/source/FreeRTOS_Stream_Buffer.c @@ -341,7 +341,7 @@ size_t uxStreamBufferAdd( StreamBuffer_t * pxBuffer, pxBuffer->uxFront = uxNextHead; } } - xTaskResumeAll(); + ( void ) xTaskResumeAll(); } return uxCount; diff --git a/test/Coverity/ConfigFiles/pack_struct_end.h b/test/Coverity/ConfigFiles/pack_struct_end.h index 91eb56854f..065de823eb 100644 --- a/test/Coverity/ConfigFiles/pack_struct_end.h +++ b/test/Coverity/ConfigFiles/pack_struct_end.h @@ -36,5 +36,6 @@ * placement in memory. */ /* The language extension is used in a portable manner for each specific compiler */ -/* coverity[misra_c_2012_rule_1_2_violation]*/ +/* coverity[misra_c_2012_rule_1_2_violation] */ +/* coverity[caretline] */ __attribute__( ( packed ) ); From d31e50e7f762495578ae1a8d2d1f879f5ce3a979 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Mon, 1 Aug 2022 09:59:21 -0700 Subject: [PATCH 2/3] Fixing spell check error --- .github/lexicon.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/lexicon.txt b/.github/lexicon.txt index c23d181a21..1ea58fbfd5 100644 --- a/.github/lexicon.txt +++ b/.github/lexicon.txt @@ -93,6 +93,7 @@ callbacklist calloc cambridge camen +caretline carriersense castingmacrofunctions cbmc From 323258bca7146599940dfde39c09d93981602927 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Mon, 1 Aug 2022 16:33:02 -0700 Subject: [PATCH 3/3] Added comment for PR review --- source/FreeRTOS_DNS_Cache.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/FreeRTOS_DNS_Cache.c b/source/FreeRTOS_DNS_Cache.c index 110245c737..b85a893c3e 100644 --- a/source/FreeRTOS_DNS_Cache.c +++ b/source/FreeRTOS_DNS_Cache.c @@ -173,6 +173,10 @@ { /* Element found */ if( xLookUp == pdTRUE ) { + /* This statement can only be reached when xResult is true; which + * implies that the entry is present and a 'get' operation will result + * in success. Therefore, it is safe to ignore the return value of the + * below function. */ ( void ) prvGetCacheIPEntry( uxIndex, pulIP, ulCurrentTimeSeconds );