From 4a3527b2ced5fe31b82acdc7e87cf71a33eb1aeb Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 15 Mar 2023 22:13:50 +0000 Subject: [PATCH 1/2] Correct GCC warnings Corrects warnings with current GCC flags for GCC 7.5.0. The only suppressed warning pertains to function to object pointer conversion which is required and common for socket callbacks. --- CMakeLists.txt | 5 --- source/CMakeLists.txt | 7 ++-- source/FreeRTOS_IP.c | 2 +- source/FreeRTOS_Sockets.c | 3 ++ source/FreeRTOS_TCP_IP.c | 37 ++++++++++++------- source/FreeRTOS_UDP_IP.c | 3 +- .../BufferManagement/BufferAllocation_2.c | 3 +- .../build-combination/Common/FreeRTOSConfig.h | 11 ++++-- 8 files changed, 41 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e4ee7e8d5..4b9a5692ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,11 +161,6 @@ else() endif() endif() -######################################################################## -# Requirements -set(CMAKE_C_STANDARD 90) # Note FreeRTOS-Kernel uses C99 constructs. -set(CMAKE_C_STANDARD_REQUIRED ON) - ######################################################################## # Overall Compile Options # Note the compile option strategy is to error on everything and then diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index a990fe9478..bff59a3f4f 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,5 +1,7 @@ add_library( freertos_plus_tcp STATIC ) +set_property(TARGET freertos_plus_tcp PROPERTY C_STANDARD 90) + target_sources( freertos_plus_tcp PRIVATE include/FreeRTOS_ARP.h @@ -74,10 +76,7 @@ target_compile_options( freertos_plus_tcp $<$:-Wno-shorten-64-to-32> $<$:-Wno-sign-conversion> $<$:-Wno-unused-macros> - $<$:-Wno-unused-but-set-variable> - $<$:-Wno-unused-parameter> - $<$:-Wno-unused-variable> - $<$:-Wno-pedantic> + $<$:-Wno-unused-parameter> ) target_link_libraries( freertos_plus_tcp diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index df777be9ab..a77e7f4fbe 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1002,10 +1002,10 @@ void FreeRTOS_ReleaseUDPPayloadBuffer( void const * pvBuffer ) static uint16_t usSequenceNumber = 0; uint8_t * pucChar; size_t uxTotalLength; + BaseType_t xEnoughSpace; IPStackEvent_t xStackTxEvent = { eStackTxEvent, NULL }; uxTotalLength = uxNumberOfBytesToSend + sizeof( ICMPPacket_t ); - BaseType_t xEnoughSpace; if( uxNumberOfBytesToSend < ( ipconfigNETWORK_MTU - ( sizeof( IPHeader_t ) + sizeof( ICMPHeader_t ) ) ) ) { diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 972cb18c9d..aa5fe7549f 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -1987,7 +1987,10 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-111 */ /* coverity[misra_c_2012_rule_11_8_violation] */ /* coverity[misra_c_2012_rule_11_1_violation] */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpedantic" pxSocket->pxUserWakeCallback = ( SocketWakeupCallback_t ) pvOptionValue; + #pragma GCC diagnostic pop xReturn = 0; break; #endif /* ipconfigSOCKET_HAS_USER_WAKE_CALLBACK */ diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 995173573d..0451be8a9b 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -634,28 +634,37 @@ /* Function might modify the parameter. */ NetworkBufferDescriptor_t * pxNetworkBuffer = pxDescriptor; - configASSERT( pxNetworkBuffer != NULL ); - configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); - /* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */ - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) - &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); + ProtocolHeaders_t * pxProtocolHeaders; FreeRTOS_Socket_t * pxSocket; - uint16_t ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags; + uint16_t ucTCPFlags; uint32_t ulLocalIP; - uint16_t usLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort ); - uint16_t usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort ); + uint16_t usLocalPort; + uint16_t usRemotePort; uint32_t ulRemoteIP; - uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); - uint32_t ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr ); - BaseType_t xResult = pdPASS; + uint32_t ulSequenceNumber; + uint32_t ulAckNumber; + BaseType_t xResult; const IPHeader_t * pxIPHeader; + configASSERT( pxNetworkBuffer != NULL ); + configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); + + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + pxProtocolHeaders = ( ( ProtocolHeaders_t * ) + &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); + + ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags; + usLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort ); + usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort ); + ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); + ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr ); + xResult = pdPASS; + /* Check for a minimum packet size. */ if( pxNetworkBuffer->xDataLength < ( ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) + ipSIZE_OF_TCP_HEADER ) ) { diff --git a/source/FreeRTOS_UDP_IP.c b/source/FreeRTOS_UDP_IP.c index b5249e4302..276fda1f75 100644 --- a/source/FreeRTOS_UDP_IP.c +++ b/source/FreeRTOS_UDP_IP.c @@ -310,6 +310,7 @@ BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffe { BaseType_t xReturn = pdPASS; FreeRTOS_Socket_t * pxSocket; + UDPPacket_t * pxUDPPacket; configASSERT( pxNetworkBuffer != NULL ); configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); @@ -319,7 +320,7 @@ BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffe /* MISRA Ref 11.3.1 [Misaligned access] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ - const UDPPacket_t * pxUDPPacket = ( ( const UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + pxUDPPacket = ( ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); /* Caller must check for minimum packet size. */ pxSocket = pxUDPSocketLookup( usPort ); diff --git a/source/portable/BufferManagement/BufferAllocation_2.c b/source/portable/BufferManagement/BufferAllocation_2.c index c3baacc3d3..e82fffaf8d 100644 --- a/source/portable/BufferManagement/BufferAllocation_2.c +++ b/source/portable/BufferManagement/BufferAllocation_2.c @@ -73,11 +73,10 @@ #define ASSERT_CONCAT_( a, b ) a ## b #define ASSERT_CONCAT( a, b ) ASSERT_CONCAT_( a, b ) #define STATIC_ASSERT( e ) \ - ; enum { ASSERT_CONCAT( assert_line_, __LINE__ ) = 1 / ( !!( e ) ) } + enum { ASSERT_CONCAT( assert_line_, __LINE__ ) = 1 / ( !!( e ) ) } STATIC_ASSERT( ipconfigETHERNET_MINIMUM_PACKET_BYTES <= baMINIMAL_BUFFER_SIZE ); #endif - /* A list of free (available) NetworkBufferDescriptor_t structures. */ static List_t xFreeBuffersList; diff --git a/test/build-combination/Common/FreeRTOSConfig.h b/test/build-combination/Common/FreeRTOSConfig.h index a7f7d86bad..30fea81c63 100644 --- a/test/build-combination/Common/FreeRTOSConfig.h +++ b/test/build-combination/Common/FreeRTOSConfig.h @@ -116,13 +116,18 @@ /* The function that implements FreeRTOS printf style output, and the macro * that maps the configPRINTF() macros to that function. */ -#define configPRINTF( X ) +void vLoggingPrintf( char const * pcFormat, + ... ); + +/* The function that implements FreeRTOS printf style output, and the macro + * that maps the configPRINTF() macros to that function. */ +#define configPRINTF( X ) vLoggingPrintf X /* Non-format version thread-safe print. */ -#define configPRINT( X ) +#define configPRINT( X ) vLoggingPrintf X /* Non-format version thread-safe print. */ -#define configPRINT_STRING( X ) +#define configPRINT_STRING( X ) vLoggingPrintf X /* Application specific definitions follow. **********************************/ From 45902f1f77689f361ccf3aebd3c71f74794638ec Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Fri, 17 Mar 2023 16:26:34 -0700 Subject: [PATCH 2/2] PR feedback --- CMakeLists.txt | 2 +- source/FreeRTOS_Sockets.c | 3 --- source/FreeRTOS_TCP_IP.c | 3 +-- source/FreeRTOS_UDP_IP.c | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b9a5692ef..ec0a264f01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,9 +190,9 @@ add_compile_options( $<$:-Wall> $<$:-Wextra> - $<$:-Wpedantic> $<$:-Werror> $<$:-Weverything> + $<$:-Wpedantic> # TODO: Add in other Compilers here. ) diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index aa5fe7549f..972cb18c9d 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -1987,10 +1987,7 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-111 */ /* coverity[misra_c_2012_rule_11_8_violation] */ /* coverity[misra_c_2012_rule_11_1_violation] */ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wpedantic" pxSocket->pxUserWakeCallback = ( SocketWakeupCallback_t ) pvOptionValue; - #pragma GCC diagnostic pop xReturn = 0; break; #endif /* ipconfigSOCKET_HAS_USER_WAKE_CALLBACK */ diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 0451be8a9b..f586a15b65 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -645,7 +645,7 @@ uint32_t ulRemoteIP; uint32_t ulSequenceNumber; uint32_t ulAckNumber; - BaseType_t xResult; + BaseType_t xResult = pdPASS; const IPHeader_t * pxIPHeader; @@ -663,7 +663,6 @@ usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort ); ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr ); - xResult = pdPASS; /* Check for a minimum packet size. */ if( pxNetworkBuffer->xDataLength < ( ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) + ipSIZE_OF_TCP_HEADER ) ) diff --git a/source/FreeRTOS_UDP_IP.c b/source/FreeRTOS_UDP_IP.c index 276fda1f75..43865d9e67 100644 --- a/source/FreeRTOS_UDP_IP.c +++ b/source/FreeRTOS_UDP_IP.c @@ -310,7 +310,7 @@ BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffe { BaseType_t xReturn = pdPASS; FreeRTOS_Socket_t * pxSocket; - UDPPacket_t * pxUDPPacket; + const UDPPacket_t * pxUDPPacket; configASSERT( pxNetworkBuffer != NULL ); configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );