Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misra rule 11.3, 11.4 suppression and 4.6 fix #512

Merged
merged 20 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/FreeRTOS_ARP.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ static void vProcessARPPacketReply( ARPPacket_t * pxARPFrame,

if( pxARPWaitingNetworkBuffer != NULL )
{
/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
IPPacket_t * pxARPWaitingIPPacket = ( ( IPPacket_t * ) pxARPWaitingNetworkBuffer->pucEthernetBuffer );
IPHeader_t * pxARPWaitingIPHeader = &( pxARPWaitingIPPacket->xIPHeader );

Expand Down Expand Up @@ -401,6 +404,10 @@ BaseType_t xIsIPInARPCache( uint32_t ulAddressToLookup )
BaseType_t xCheckRequiresARPResolution( NetworkBufferDescriptor_t * pxNetworkBuffer )
{
BaseType_t xNeedsARPResolution = pdFALSE;

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );
IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader );

Expand Down Expand Up @@ -1071,6 +1078,9 @@ void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffe
configASSERT( pxNetworkBuffer != NULL );
configASSERT( pxNetworkBuffer->xDataLength >= sizeof( ARPPacket_t ) );

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxARPPacket = ( ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );

/* memcpy the const part of the header information into the correct
Expand Down Expand Up @@ -1141,6 +1151,10 @@ void FreeRTOS_ClearARP( void )
{
BaseType_t xResult = pdFALSE;
NetworkBufferDescriptor_t * pxUseDescriptor = pxDescriptor;

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
const IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxUseDescriptor->pucEthernetBuffer );

if( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE )
Expand Down
13 changes: 13 additions & 0 deletions source/FreeRTOS_DHCP.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@
{
xDHCPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );

/* MISRA Rule 11.4 warns about casting pointer to a different type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which cast is being referenced here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change the wording here. It's a conversion.

* The casting here is to use pointer to pass error code.
* The pointer will be checked against the error code value
* before any further pointer action. */
/* coverity[misra_c_2012_rule_11_4_violation] */
if( xDHCPSocket != FREERTOS_INVALID_SOCKET )
{
/* Ensure the Rx and Tx timeouts are zero as the DHCP executes in the
Expand Down Expand Up @@ -732,6 +737,10 @@
if( lBytes > 0 )
{
/* Map a DHCP structure onto the received data. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayload );

/* Sanity check. */
Expand Down Expand Up @@ -1011,6 +1020,10 @@
{
/* Leave space for the UDP header. */
pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayloadBuffer );

/* Most fields need to be zero. */
Expand Down
12 changes: 12 additions & 0 deletions source/FreeRTOS_DNS.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@
{
uint32_t ulIPAddress = 0UL;
BaseType_t xExpected;

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
const DNSMessage_t * pxDNSMessageHeader =
( ( const DNSMessage_t * )
pxReceiveBuffer->pucPayloadBuffer );
Expand Down Expand Up @@ -668,6 +672,10 @@

/* Write in a unique identifier. Cast the Payload Buffer to DNSMessage_t
* to easily access fields of the DNS Message. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxDNSMessageHeader = ( ( DNSMessage_t * ) pucUDPPayloadBuffer );
pxDNSMessageHeader->usIdentifier = ( uint16_t ) uxIdentifier;

Expand Down Expand Up @@ -709,6 +717,10 @@

/* Finish off the record. Cast the record onto DNSTail_t structure to easily
* access the fields of the DNS Message. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxTail = ( ( DNSTail_t * ) &( pucUDPPayloadBuffer[ uxStart + 1U ] ) );

#if defined( _lint ) || defined( __COVERITY__ )
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_DNS_Cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
BaseType_t x;

/* For each entry in the DNS cache table. */
for( x = 0; x < ( int ) ipconfigDNS_CACHE_ENTRIES; x++ )
for( x = 0; x < ipconfigDNS_CACHE_ENTRIES; x++ )
{
if( xDNSCache[ x ].pcName[ 0 ] == ( char ) 0 )
{ /* empty slot */
Expand Down
12 changes: 12 additions & 0 deletions source/FreeRTOS_DNS_Parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@

/* Parse the DNS message header. Map the byte stream onto a structure
* for easier access. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxDNSMessageHeader = ( ( DNSMessage_t * )
pucUDPPayloadBuffer );

Expand Down Expand Up @@ -609,6 +613,10 @@

/* Mapping pucBuffer to a DNSAnswerRecord allows easy access of the
* fields of the structure. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucBuffer );

/* Sanity check the data length of an IPv4 answer. */
Expand Down Expand Up @@ -683,6 +691,10 @@
/* It's not an A record, so skip it. Get the header location
* and then jump over the header. */
/* Cast the response to DNSAnswerRecord for easy access to fields of the DNS response. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucBuffer );

pucBuffer = &( pucBuffer[ sizeof( DNSAnswerRecord_t ) ] );
Expand Down
4 changes: 4 additions & 0 deletions source/FreeRTOS_ICMP.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
{
/* Map the buffer onto a ICMP-Packet struct to easily access the
* fields of ICMP packet. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
ICMPPacket_t * pxICMPPacket = ( ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );

switch( pxICMPPacket->xICMPHeader.ucTypeOfMessage )
Expand Down
30 changes: 30 additions & 0 deletions source/FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,10 @@ eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucE
const EthernetHeader_t * pxEthernetHeader;

/* Map the buffer onto Ethernet Header struct for easy access to fields. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxEthernetHeader = ( ( const EthernetHeader_t * ) pucEthernetBuffer );

if( memcmp( ipLOCAL_MAC_ADDRESS, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 )
Expand Down Expand Up @@ -1225,6 +1229,10 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
eReturned = ipCONSIDER_FRAME_FOR_PROCESSING( pxNetworkBuffer->pucEthernetBuffer );

/* Map the buffer onto the Ethernet Header struct for easy access to the fields. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxEthernetHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer );

/* The condition "eReturned == eProcessBuffer" must be true. */
Expand All @@ -1240,6 +1248,9 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
/* The Ethernet frame contains an ARP packet. */
if( pxNetworkBuffer->xDataLength >= sizeof( ARPPacket_t ) )
{
/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
eReturned = eARPProcessPacket( ( ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ) );
}
else
Expand All @@ -1254,6 +1265,9 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
/* The Ethernet frame contains an IP packet. */
if( pxNetworkBuffer->xDataLength >= sizeof( IPPacket_t ) )
{
/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
eReturned = prvProcessIPPacket( ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer );
}
else
Expand Down Expand Up @@ -1512,6 +1526,10 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP
ProtocolPacket_t * pxProtPack;

/* pxProtPack will point to the offset were the protocols begin. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxProtPack = ( ( ProtocolPacket_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );

if( pxProtPack->xUDPPacket.xUDPHeader.usChecksum == ( uint16_t ) 0U )
Expand Down Expand Up @@ -1665,6 +1683,10 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,

/* Map the buffer onto a UDP-Packet struct to easily access the
* fields of UDP packet. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
const UDPPacket_t * pxUDPPacket = ( ( const UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );
uint16_t usLength;
BaseType_t xIsWaitingARPResolution = pdFALSE;
Expand Down Expand Up @@ -1796,6 +1818,10 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,

/* Map the buffer onto a IP-Packet struct to easily access the
* fields of the IP packet. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer );

ucVersionHeaderLength = pxIPPacket->xIPHeader.ucVersionHeaderLength;
Expand Down Expand Up @@ -1945,6 +1971,10 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
#endif /* if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) */
{
/* Map the Buffer to Ethernet Header struct for easy access to fields. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxEthernetHeader = ( ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer );

/*
Expand Down
15 changes: 14 additions & 1 deletion source/FreeRTOS_IP_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ static NetworkBufferDescriptor_t * prvPacketBuffer_to_NetworkBuffer( const void
/* The following statement may trigger a:
* warning: cast increases required alignment of target type [-Wcast-align].
* It has been confirmed though that the alignment is suitable. */
/* coverity[misra_c_2012_rule_11_4_violation] */
pxResult = *( ( NetworkBufferDescriptor_t ** ) uxBuffer );
}
else
Expand Down Expand Up @@ -461,6 +462,10 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer,
}

/* Parse the packet length. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer );

/* Per https://tools.ietf.org/html/rfc791, the four-bit Internet Header
Expand Down Expand Up @@ -502,6 +507,10 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer,
* and IP headers incorrectly aligned. However, either way, the "third"
* protocol (Layer 3 or 4) header will be aligned, which is the convenience
* of this calculation. */

/* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type.
* To be able to access various predefined fields from a data buffer, this mapping is intentional. */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxProtPack = ( ( ProtocolPacket_t * ) &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );

/* Switch on the Layer 3/4 protocol. */
Expand Down Expand Up @@ -825,6 +834,10 @@ uint16_t usGenerateChecksum( uint16_t usSum,
xTerm.u32 = 0UL;

xSource.u8ptr = ipPOINTER_CAST( uint8_t *, pucNextData );

/* MISRA Rule 11.4 warns about casting pointer to a different size of pointer.
* The casting is used here to help checksum calculation. It is intentional */
/* coverity[misra_c_2012_rule_11_4_violation] */
uxAlignBits = ( ( ( uintptr_t ) pucNextData ) & 0x03U );

/*
Expand Down Expand Up @@ -1109,7 +1122,7 @@ const char * FreeRTOS_strerror_r( BaseType_t xErrnum,

default:
/* Using function "snprintf". */
( void ) snprintf( pcBuffer, uxLength, "Errno %d", ( int ) xErrnum );
( void ) snprintf( pcBuffer, uxLength, "Errno %d", ( int32_t ) xErrnum );
pcName = NULL;
break;
}
Expand Down
Loading