From ded3d27f62528f2d20b8cdcf837e4cfd9264a5ef Mon Sep 17 00:00:00 2001 From: Kody Stribrny <89810515+kstribrnAmzn@users.noreply.github.com> Date: Tue, 21 Mar 2023 09:32:59 -0700 Subject: [PATCH] Correct GCC warnings (#798) * 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. * PR feedback --------- Co-authored-by: Ubuntu Co-authored-by: Nikhil Kamath <110539926+amazonKamath@users.noreply.github.com> --- CMakeLists.txt | 7 +--- source/CMakeLists.txt | 7 ++-- source/FreeRTOS_IP.c | 2 +- source/FreeRTOS_TCP_IP_IPV4.c | 34 +++++++++++-------- source/FreeRTOS_UDP_IPv4.c | 3 +- .../BufferManagement/BufferAllocation_2.c | 3 +- .../build-combination/Common/FreeRTOSConfig.h | 11 ++++-- 7 files changed, 35 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af76aa226..fb77d3775 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 @@ -195,10 +190,10 @@ add_compile_options( $<$:-Wall> $<$:-Wextra> - $<$:-Wpedantic> $<$:-Werror> $<$:-Wunused-variable> $<$:-Weverything> + $<$:-Wpedantic> # TODO: Add in other Compilers here. ) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 5e096d5f8..dad2e1168 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/FreeRTOSIPConfigDefaults.h @@ -108,10 +110,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 180bb221d..49d49addf 100755 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1254,10 +1254,10 @@ void FreeRTOS_SetEndPointConfiguration( const uint32_t * pulIPAddress, 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_TCP_IP_IPV4.c b/source/FreeRTOS_TCP_IP_IPV4.c index a56f4d667..4ff2e079a 100644 --- a/source/FreeRTOS_TCP_IP_IPV4.c +++ b/source/FreeRTOS_TCP_IP_IPV4.c @@ -98,28 +98,32 @@ { /* Function might modify the parameter. */ NetworkBufferDescriptor_t * pxNetworkBuffer = pxDescriptor; + FreeRTOS_Socket_t * pxSocket; + uint16_t ucTCPFlags; + uint32_t ulLocalIP; + uint16_t usLocalPort; + uint16_t usRemotePort; + IP_Address_t ulRemoteIP; + uint32_t ulSequenceNumber; + uint32_t ulAckNumber; + BaseType_t xResult = pdPASS; + + const IPHeader_t * pxIPHeader; 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 + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); - FreeRTOS_Socket_t * pxSocket; - uint16_t ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags; - uint32_t ulLocalIP; - uint16_t usLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort ); - uint16_t usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort ); - IP_Address_t ulRemoteIP; - uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); - uint32_t ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr ); - BaseType_t xResult = pdPASS; - - const IPHeader_t * pxIPHeader; + 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 ); /* Check for a minimum packet size. */ if( pxNetworkBuffer->xDataLength < ( ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) + ipSIZE_OF_TCP_HEADER ) ) diff --git a/source/FreeRTOS_UDP_IPv4.c b/source/FreeRTOS_UDP_IPv4.c index b286ce989..67f6d26f8 100644 --- a/source/FreeRTOS_UDP_IPv4.c +++ b/source/FreeRTOS_UDP_IPv4.c @@ -337,6 +337,7 @@ BaseType_t xProcessReceivedUDPPacket_IPv4( NetworkBufferDescriptor_t * pxNetwork { BaseType_t xReturn = pdPASS; FreeRTOS_Socket_t * pxSocket; + const UDPPacket_t * pxUDPPacket; configASSERT( pxNetworkBuffer != NULL ); configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); @@ -346,7 +347,7 @@ BaseType_t xProcessReceivedUDPPacket_IPv4( NetworkBufferDescriptor_t * pxNetwork /* 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 ); const NetworkEndPoint_t * pxEndpoint = pxNetworkBuffer->pxEndPoint; /* Caller must check for minimum packet size. */ diff --git a/source/portable/BufferManagement/BufferAllocation_2.c b/source/portable/BufferManagement/BufferAllocation_2.c index 77a9a32d6..075cdf0a7 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 432b82b9d..9b68fb1b0 100644 --- a/test/build-combination/Common/FreeRTOSConfig.h +++ b/test/build-combination/Common/FreeRTOSConfig.h @@ -111,13 +111,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. **********************************/