Skip to content

Commit

Permalink
Fix MISRA issue (#1049)
Browse files Browse the repository at this point in the history
Fix following MISRA issues :

MISRA Rule 8_5 : Symbol "FreeRTOS_inet_ntop6" is declared more than once.
MISRA Rule 8_9 : Symbol "FreeRTOS_in6addr_loopback" should be defined at block scope.
MISRA Rule 8_8 : missing static storage modifier for "prvCloseDHCPSocket" which has internal linkage.
MISRA Rule 9_1 : Using uninitialized value "xRemoteIP.xIs_IPv6" when calling "pxTCPSocketLookup".
MISRA Rule 9_1 : Using uninitialized value "pxAddress->sin_family" when calling "prvSocketBindAdd".
MISRA Rule 11_3 : A cast shall not be performed between two pointer of different object type.
MISRA Rule 12_1 : Missing parentheses on sub-expression of the operator.
MISRA Rule 14.4 : The condition expression 0 does not have an essentially boolean type
MISRA Rule 15_6 : The body of the "then" branch of the "if" statement is not a compound statement.
MISRA Rule 17_7 : The return value of a non-void function "memset" is unused.
MISRA Rule 20_5 : Using "#undef".
MISRA Rule 20_10 : Use of "#" or "##" preprocessor operator.
MISRA Rule 21_1 : Defining or undefining a reserved name "_static", which is an identifier or macro name beginning with an underscore.
MISRA Rule 21_15 : Calling function "memcmp" with incompatible types "void " and "uint8_t const ()[6]".
  • Loading branch information
moninom1 authored Dec 8, 2023
1 parent d70a21c commit c8d98d4
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 35 deletions.
10 changes: 5 additions & 5 deletions source/FreeRTOS_ARP.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ static TickType_t xLastGratuitousARPTime = 0U;

if( ulTargetProtocolAddress == pxTargetEndPoint->ipv4_settings.ulIPAddress )
{
if( memcmp( ( void * ) pxTargetEndPoint->xMACAddress.ucBytes,
( pxARPHeader->xSenderHardwareAddress.ucBytes ),
if( memcmp( pxTargetEndPoint->xMACAddress.ucBytes,
pxARPHeader->xSenderHardwareAddress.ucBytes,
ipMAC_ADDRESS_LENGTH_BYTES ) != 0 )
{
vARPProcessPacketRequest( pxARPFrame, pxTargetEndPoint, ulSenderProtocolAddress );
Expand All @@ -310,9 +310,9 @@ static TickType_t xLastGratuitousARPTime = 0U;

/* Make sure target MAC address is either ff:ff:ff:ff:ff:ff or 00:00:00:00:00:00 and senders MAC
* address is not matching with the endpoint MAC address. */
if( ( ( memcmp( ( const void * ) pxARPHeader->xTargetHardwareAddress.ucBytes, xBroadcastMACAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 ) ||
( ( memcmp( ( const void * ) pxARPHeader->xTargetHardwareAddress.ucBytes, xGARPTargetAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 ) ) ) &&
( memcmp( ( void * ) pxTargetEndPoint->xMACAddress.ucBytes, ( pxARPHeader->xSenderHardwareAddress.ucBytes ), ipMAC_ADDRESS_LENGTH_BYTES ) != 0 ) )
if( ( ( memcmp( pxARPHeader->xTargetHardwareAddress.ucBytes, xBroadcastMACAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 ) ||
( ( memcmp( pxARPHeader->xTargetHardwareAddress.ucBytes, xGARPTargetAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 ) ) ) &&
( memcmp( pxTargetEndPoint->xMACAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES ) != 0 ) )
{
MACAddress_t xHardwareAddress;
NetworkEndPoint_t * pxCachedEndPoint;
Expand Down
4 changes: 2 additions & 2 deletions source/FreeRTOS_DHCP.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@
* using it.
* @param[in] pxEndPoint The end-point that stops using the socket.
*/
void prvCloseDHCPSocket( NetworkEndPoint_t * pxEndPoint )
static void prvCloseDHCPSocket( NetworkEndPoint_t * pxEndPoint )
{
if( ( EP_DHCPData.xDHCPSocket == NULL ) || ( EP_DHCPData.xDHCPSocket != xDHCPv4Socket ) )
{
Expand Down Expand Up @@ -905,7 +905,7 @@
( void ) FreeRTOS_setsockopt( xDHCPv4Socket, 0, FREERTOS_SO_RCVTIMEO, &( xTimeoutTime ), sizeof( TickType_t ) );
( void ) FreeRTOS_setsockopt( xDHCPv4Socket, 0, FREERTOS_SO_SNDTIMEO, &( xTimeoutTime ), sizeof( TickType_t ) );

memset( &xAddress, 0, sizeof( xAddress ) );
( void ) memset( &xAddress, 0, sizeof( xAddress ) );
xAddress.sin_family = FREERTOS_AF_INET4;
xAddress.sin_len = ( uint8_t ) sizeof( xAddress );
/* Bind to the standard DHCP client port. */
Expand Down
4 changes: 1 addition & 3 deletions source/FreeRTOS_DNS.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,7 @@
/* 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 DNSMessage_t * pxDNSMessageHeader =
( ( const DNSMessage_t * )
pxReceiveBuffer->pucPayloadBuffer );
const DNSMessage_t * pxDNSMessageHeader = ( const DNSMessage_t * ) pxReceiveBuffer->pucPayloadBuffer;

#if ( ipconfigUSE_MDNS == 1 )
/* _HT_ changed 'pxReceiveBuffer->sin_port' to 'usPort' */
Expand Down
3 changes: 3 additions & 0 deletions source/FreeRTOS_IPv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const struct xIPv6_Address FreeRTOS_in6addr_any = { 0 };
/**
* This variable is initialized by the system to contain the loopback IPv6 address.
*/
/* 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] */
const struct xIPv6_Address FreeRTOS_in6addr_loopback = { { 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U } };

#if ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 1 )
Expand Down
4 changes: 4 additions & 0 deletions source/FreeRTOS_RA.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxICMPPacket = ( ( ICMPPacket_IPv6_t * ) pxDescriptor->pucEthernetBuffer );

/* 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] */
xRASolicitationRequest = ( ( ICMPRouterSolicitation_IPv6_t * ) &( pxICMPPacket->xICMPHeaderIPv6 ) );

pxDescriptor->xDataLength = uxNeededSize;
Expand Down
13 changes: 11 additions & 2 deletions source/FreeRTOS_Sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1926,8 +1926,17 @@ BaseType_t vSocketBind( FreeRTOS_Socket_t * pxSocket,
if( pxAddress == NULL )
{
pxAddress = &xAddress;
/* Put the port to zero to be assigned later. */
pxAddress->sin_port = 0U;
/* Clear the address: */
( void ) memset( pxAddress, 0, sizeof( struct freertos_sockaddr ) );

if( pxSocket->bits.bIsIPv6 != pdFALSE_UNSIGNED )
{
pxAddress->sin_family = FREERTOS_AF_INET6;
}
else
{
pxAddress->sin_family = FREERTOS_AF_INET;
}
}
}
#endif /* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 1 */
Expand Down
1 change: 1 addition & 0 deletions source/FreeRTOS_TCP_IP_IPv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ BaseType_t xProcessReceivedTCPPacket_IPV6( NetworkBufferDescriptor_t * pxDescrip
/* coverity[misra_c_2012_rule_11_3_violation] */
const IPHeader_IPv6_t * pxIPHeader_IPv6 = ( ( IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
( void ) memcpy( xRemoteIP.xIPAddress.xIP_IPv6.ucBytes, pxIPHeader_IPv6->xSourceAddress.ucBytes, sizeof( IPv6_Address_t ) );
xRemoteIP.xIs_IPv6 = pdTRUE;

/* Find the destination socket, and if not found: return a socket listing to
* the destination PORT. */
Expand Down
20 changes: 15 additions & 5 deletions source/include/FreeRTOSIPConfigDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
*/

#ifndef _static
/* suppressing the use of _static as it is used for other tools like cbmc */
/* coverity[misra_c_2012_rule_21_1_violation] */
/* coverity[misra_c_2012_rule_21_2_violation] */
#define _static static
#endif

Expand Down Expand Up @@ -3063,8 +3066,8 @@
#endif

#ifndef FreeRTOS_debug_printf
#ifdef configPRINTF
#define FreeRTOS_debug_printf( MSG ) if( ipconfigHAS_DEBUG_PRINTF ) configPRINTF( MSG )
#if ( ( ipconfigHAS_DEBUG_PRINTF == 1 ) && defined( configPRINTF ) )
#define FreeRTOS_debug_printf( MSG ) do { configPRINTF( MSG ); } while( ipFALSE_BOOL )
#else
#define FreeRTOS_debug_printf( MSG ) do {} while( ipFALSE_BOOL )
#endif
Expand Down Expand Up @@ -3099,8 +3102,8 @@
#endif

#ifndef FreeRTOS_printf
#ifdef configPRINTF
#define FreeRTOS_printf( MSG ) if( ipconfigHAS_PRINTF ) configPRINTF( MSG )
#if ( ( ipconfigHAS_PRINTF == 1 ) && defined( configPRINTF ) )
#define FreeRTOS_printf( MSG ) do { configPRINTF( MSG ); } while( ipFALSE_BOOL )
#else
#define FreeRTOS_printf( MSG ) do {} while( ipFALSE_BOOL )
#endif
Expand All @@ -3119,7 +3122,14 @@
*/

#ifndef FreeRTOS_flush_logging
#define FreeRTOS_flush_logging() if( ipconfigHAS_PRINTF || ipconfigHAS_DEBUG_PRINTF ) do {} while( ipFALSE_BOOL )
#define FreeRTOS_flush_logging() \
if( ipconfigHAS_PRINTF || ipconfigHAS_DEBUG_PRINTF ) \
{ \
do {} while( ipFALSE_BOOL ); \
} \
else \
{ \
}
#endif

/*---------------------------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion source/include/FreeRTOS_IPv6_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@

/* The offset into an IP packet into which the IP data (payload) starts. */
#define ipIPv6_PAYLOAD_OFFSET ( sizeof( IPPacket_IPv6_t ) )
/* The maximum UDP payload length. */
/* MISRA Ref 20.5.1 [Use of undef] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2051 */
/* coverity[misra_c_2012_rule_20_5_violation] */
/* The maximum UDP payload length. */
#undef ipMAX_UDP_PAYLOAD_LENGTH
#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv6_HEADER ) - ipSIZE_OF_UDP_HEADER )
/* The offset into a UDP packet at which the UDP data (payload) starts. */
Expand Down
7 changes: 0 additions & 7 deletions source/include/FreeRTOS_IPv6_Sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@
*/
void prv_ntop6_search_zeros( struct sNTOP6_Set * pxSet );

/*
* Convert a string like 'fe80::8d11:cd9b:8b66:4a80'
* to a 16-byte IPv6 address
*/
const char * FreeRTOS_inet_ntop6( const void * pvSource,
char * pcDestination,
socklen_t uxSize );

/** @brief Called by pxTCPSocketLookup(), this function will check if a socket
* is connected to a remote IP-address. It will be called from a loop
Expand Down
8 changes: 4 additions & 4 deletions source/portable/BufferManagement/BufferAllocation_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
/* Compile time assertion with zero runtime effects
* it will assert on 'e' not being zero, as it tries to divide by it,
* will also print the line where the error occurred in case of failure */
/* MISRA Ref 20.10.1 [Lack of sizeof operator and compile time error checking] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2010 */
/* coverity[misra_c_2012_rule_20_10_violation] */
#if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
/* MISRA Ref 20.10.1 [Lack of sizeof operator and compile time error checking] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2010 */
/* coverity[misra_c_2012_rule_20_10_violation] */
#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
Expand Down
7 changes: 1 addition & 6 deletions test/cbmc/patches/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#ifndef ipconfigHAS_DEBUG_PRINTF
#define ipconfigHAS_DEBUG_PRINTF 0
#endif
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
#define FreeRTOS_debug_printf( X )

/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
Expand Down

0 comments on commit c8d98d4

Please sign in to comment.