Skip to content

Commit

Permalink
Correct GCC warnings (FreeRTOS#798)
Browse files Browse the repository at this point in the history
* 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 <ubuntu@ip-10-0-137-67.ec2.internal>
Co-authored-by: Nikhil Kamath <110539926+amazonKamath@users.noreply.github.com>
  • Loading branch information
3 people authored and moninom1 committed Apr 18, 2023
1 parent 63fe99f commit ded3d27
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -195,10 +190,10 @@ add_compile_options(

$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wall>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wpedantic>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wunused-variable>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wpedantic>

# TODO: Add in other Compilers here.
)
Expand Down
7 changes: 3 additions & 4 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -108,10 +110,7 @@ target_compile_options( freertos_plus_tcp
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-shorten-64-to-32>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-sign-conversion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-unused-but-set-variable>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wno-unused-parameter>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-unused-variable>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-pedantic>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-parameter>
)

target_link_libraries( freertos_plus_tcp
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) ) )
{
Expand Down
34 changes: 19 additions & 15 deletions source/FreeRTOS_TCP_IP_IPV4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down
3 changes: 2 additions & 1 deletion source/FreeRTOS_UDP_IPv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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. */
Expand Down
3 changes: 1 addition & 2 deletions source/portable/BufferManagement/BufferAllocation_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 8 additions & 3 deletions test/build-combination/Common/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. **********************************/

Expand Down

0 comments on commit ded3d27

Please sign in to comment.