From cad1f7590f62cc7f400f448fa0af8814ab7e5544 Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Thu, 10 Oct 2024 13:32:00 +0530 Subject: [PATCH] Fix MISRA2012 issues with Coverity version 2024.06 (#1196) * MISRA fix * More MISRA fixes * Add exception for Rule 17.11 * Fix comments * Include externs inside preprocessor macros * Taking global exception for Rule 17.11 * Fix formatting --- source/FreeRTOS_ARP.c | 2 +- source/FreeRTOS_DNS.c | 56 +++++++++++++++-------------- source/FreeRTOS_IP.c | 4 +-- source/include/FreeRTOS_DNS.h | 8 +++-- test/Coverity/coverity_misra.config | 4 +++ 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 1a3dc6a47..6d279623d 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -979,7 +979,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, if( pxEndPoint != NULL ) { /* For multi-cast, use the first IPv4 end-point. */ - memcpy( pxMACAddress->ucBytes, pxEndPoint->xMACAddress.ucBytes, sizeof( pxMACAddress->ucBytes ) ); + ( void ) memcpy( pxMACAddress->ucBytes, pxEndPoint->xMACAddress.ucBytes, sizeof( pxMACAddress->ucBytes ) ); *( ppxEndPoint ) = pxEndPoint; eReturn = eARPCacheHit; } diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 82e2c6dbf..4357f4443 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -63,20 +63,22 @@ const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } /** @brief The IPv6 link-scope multicast MAC address */ const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; +#if ( ( ipconfigUSE_LLMNR != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) /** @brief The IPv6 link-scope multicast address */ -const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6 = -{ - { /* ff02::1:3 */ - 0xff, 0x02, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x01, - 0x00, 0x03, - } -}; + const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6 = + { + { /* ff02::1:3 */ + 0xff, 0x02, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x01, + 0x00, 0x03, + } + }; +#endif /* ( ( ipconfigUSE_LLMNR != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) */ /** @brief The MAC address used for MDNS. */ const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } }; @@ -84,20 +86,22 @@ const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } } /** @brief The IPv6 multicast DNS MAC address. */ const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; +#if ( ( ipconfigUSE_MDNS != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) /** @brief multicast DNS IPv6 address */ -const IPv6_Address_t ipMDNS_IP_ADDR_IPv6 = -{ - { /* ff02::fb */ - 0xff, 0x02, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0xfb, - } -}; + const IPv6_Address_t ipMDNS_IP_ADDR_IPv6 = + { + { /* ff02::fb */ + 0xff, 0x02, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0xfb, + } + }; +#endif /* ( ( ipconfigUSE_MDNS != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) */ /* Exclude the entire file if DNS is not enabled. */ #if ( ipconfigUSE_DNS != 0 ) diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 348b1e4d2..d1da10664 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -982,7 +982,7 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) { static StaticTask_t xIPTaskBuffer; static StackType_t xIPTaskStack[ ipconfigIP_TASK_STACK_SIZE_WORDS ]; - xIPTaskHandle = xTaskCreateStatic( prvIPTask, + xIPTaskHandle = xTaskCreateStatic( &prvIPTask, "IP-Task", ipconfigIP_TASK_STACK_SIZE_WORDS, NULL, @@ -997,7 +997,7 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) } #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ { - xReturn = xTaskCreate( prvIPTask, + xReturn = xTaskCreate( &prvIPTask, "IP-task", ipconfigIP_TASK_STACK_SIZE_WORDS, NULL, diff --git a/source/include/FreeRTOS_DNS.h b/source/include/FreeRTOS_DNS.h index 830e1ae2b..b9ab2e695 100644 --- a/source/include/FreeRTOS_DNS.h +++ b/source/include/FreeRTOS_DNS.h @@ -47,8 +47,10 @@ extern const MACAddress_t xLLMNR_MacAddress; /* The LLMNR IPv6 MAC address is 33:33:00:01:00:03 */ extern const MACAddress_t xLLMNR_MacAddressIPv6; +#if ( ( ipconfigUSE_LLMNR != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) /* The LLMNR IPv6 address is ff02::1:3 */ -extern const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6; + extern const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6; +#endif /* ( ( ipconfigUSE_LLMNR != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) */ /* The MDNS MAC address is 01:00:5e:00:00:fc */ extern const MACAddress_t xMDNS_MacAddress; @@ -61,8 +63,10 @@ extern const MACAddress_t xMDNS_MacAddressIPv6; /* Guarantee backward compatibility. */ #define xMDNS_MACAddressIPv6 xMDNS_MacAddressIPv6 +#if ( ( ipconfigUSE_MDNS != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) /* The MDNS IPv6 address is ff02::1:3 */ -extern const IPv6_Address_t ipMDNS_IP_ADDR_IPv6; + extern const IPv6_Address_t ipMDNS_IP_ADDR_IPv6; +#endif /* ( ( ipconfigUSE_MDNS != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) */ /** @brief While doing integration tests, it is necessary to influence the choice * between DNS/IPv4 and DNS/IPv4. Depending on this, a DNS server will be diff --git a/test/Coverity/coverity_misra.config b/test/Coverity/coverity_misra.config index 05432cd2f..e630d988e 100644 --- a/test/Coverity/coverity_misra.config +++ b/test/Coverity/coverity_misra.config @@ -42,6 +42,10 @@ deviation: "Rule 2.4", reason: "Similar to the FreeRTOS Kernel, structures are always declared with both a struct tag and typedef alias. Some of these structs are always referred to by their typedef alias and thus the corresponding tags are unused." }, + { + deviation: "Rule 17.11", + reason: "_Noreturn is added by C standard as part of C11 and the FreeRTOS+TCP codebase is compatible with C90. This is a false positive as the Coverity is also run with C90 as the standard. " + }, { deviation: "Directive 4.8", reason: "We include lots of header files from other sources such as the kernel which defines structures that violate that Dir"