From a33236a92d59c2f5b8d604630390daf654446510 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Wed, 22 Jun 2022 16:54:24 -0700 Subject: [PATCH 01/12] Misra rule 11.3 inline suppression --- source/FreeRTOS_ARP.c | 14 ++++++++++++ source/FreeRTOS_DHCP.c | 8 +++++++ source/FreeRTOS_DNS.c | 12 +++++++++++ source/FreeRTOS_DNS_Parser.c | 12 +++++++++++ source/FreeRTOS_ICMP.c | 4 ++++ source/FreeRTOS_IP.c | 30 ++++++++++++++++++++++++++ source/FreeRTOS_IP_Utils.c | 8 +++++++ source/FreeRTOS_Sockets.c | 26 ++++++++++++++++++++++ source/FreeRTOS_TCP_IP.c | 12 +++++++++++ source/FreeRTOS_TCP_Reception.c | 16 ++++++++++++++ source/FreeRTOS_TCP_State_Handling.c | 28 ++++++++++++++++++++++++ source/FreeRTOS_TCP_Transmission.c | 32 ++++++++++++++++++++++++++++ source/FreeRTOS_TCP_WIN.c | 19 +++++++++++++++++ source/FreeRTOS_UDP_IP.c | 8 +++++++ 14 files changed, 229 insertions(+) diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 1ea1d398d..2a499ee52 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -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 ); @@ -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 ); @@ -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 @@ -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 ) diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index 2fdcd0976..58d2af12c 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -732,6 +732,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. */ @@ -1011,6 +1015,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. */ diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 53f60d5e9..901ed767e 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -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 ); @@ -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; @@ -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__ ) diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index f88126de1..7e3621366 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -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 ); @@ -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. */ @@ -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 ) ] ); diff --git a/source/FreeRTOS_ICMP.c b/source/FreeRTOS_ICMP.c index 127291400..e6a6dff92 100644 --- a/source/FreeRTOS_ICMP.c +++ b/source/FreeRTOS_ICMP.c @@ -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 ) diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 31711cc92..a9dbf356e 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -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 ) @@ -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. */ @@ -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 @@ -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 @@ -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 ) @@ -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; @@ -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; @@ -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 ); /* diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 7c3cea281..9c38b3958 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -461,6 +461,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 @@ -502,6 +506,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. */ diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 718b85184..2424f4ac2 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -1629,6 +1629,10 @@ void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) static void prvTCPSetSocketCount( FreeRTOS_Socket_t const * pxSocketToDelete ) { const ListItem_t * pxIterator; + + /* 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 ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); FreeRTOS_Socket_t * pxOtherSocket; uint16_t usLocalPort = pxSocketToDelete->usLocalPort; @@ -2204,6 +2208,10 @@ static const ListItem_t * pxListFindListItemWithValue( const List_t * pxList, if( ( xIPIsNetworkTaskReady() != pdFALSE ) && ( pxList != NULL ) ) { const ListItem_t * pxIterator; + + /* 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 ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxList->xListEnd ) ); for( pxIterator = listGET_NEXT( pxEnd ); @@ -3906,7 +3914,15 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) TickType_t xNow = xTaskGetTickCount(); static TickType_t xLastTime = 0U; TickType_t xDelta = xNow - xLastTime; + + /* 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 ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); + + /* 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 ListItem_t * pxIterator = ( const ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); xLastTime = xNow; @@ -4002,6 +4018,10 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) { const ListItem_t * pxIterator; FreeRTOS_Socket_t * pxResult = NULL, * pxListenSocket = 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] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); /* Parameter not yet supported. */ @@ -4824,12 +4844,18 @@ BaseType_t xSocketValid( Socket_t xSocket ) if( xRound == 0 ) { + /* 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] */ pxEnd = ( ( const ListItem_t * ) &( xBoundUDPSocketsList.xListEnd ) ); } #if ipconfigUSE_TCP == 1 else { + /* 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] */ pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); } #endif /* ipconfigUSE_TCP == 1 */ diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 0d96dd44c..4d31dd488 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -540,6 +540,10 @@ configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); /* Map the buffer onto a ProtocolHeaders_t 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] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); FreeRTOS_Socket_t * pxSocket; @@ -562,6 +566,10 @@ else { /* Map the ethernet buffer onto the IPHeader_t 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] */ pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress ); ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress ); @@ -790,6 +798,10 @@ const ListItem_t * pxIterator; FreeRTOS_Socket_t * pxFound; BaseType_t xResult = 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] */ const ListItem_t * pxEndTCP = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); /* Here xBoundTCPSocketsList can be accessed safely IP-task is the only one diff --git a/source/FreeRTOS_TCP_Reception.c b/source/FreeRTOS_TCP_Reception.c index 8a69e7e44..cf57575b5 100644 --- a/source/FreeRTOS_TCP_Reception.c +++ b/source/FreeRTOS_TCP_Reception.c @@ -97,6 +97,10 @@ const NetworkBufferDescriptor_t * pxNetworkBuffer ) { size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ); + + /* 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 ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) ); const TCPHeader_t * pxTCPHeader; @@ -424,12 +428,20 @@ uint8_t ** ppucRecvData ) { /* Map the ethernet buffer onto the ProtocolHeader_t 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] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); const TCPHeader_t * pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength; /* Map the buffer onto an IPHeader_t 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] */ const IPHeader_t * pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); const size_t xIPHeaderLength = ipSIZE_OF_IPv4_HEADER; uint16_t usLength; @@ -510,6 +522,10 @@ uint32_t ulReceiveLength ) { /* Map the ethernet buffer onto the ProtocolHeader_t 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] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); const TCPHeader_t * pxTCPHeader = &pxProtocolHeaders->xTCPHeader; diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 711f4eb1f..50d1d392d 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -239,6 +239,10 @@ const NetworkBufferDescriptor_t * pxNetworkBuffer ) { /* Map the ethernet buffer onto the ProtocolHeader_t 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] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); TCPHeader_t * pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); @@ -350,6 +354,10 @@ UBaseType_t uxOptionsLength ) { /* Map the ethernet buffer onto the ProtocolHeader_t 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] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); TCPHeader_t * pxTCPHeader = &pxProtocolHeaders->xTCPHeader; @@ -400,6 +408,10 @@ if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN ) { /* Map the Last packet onto the ProtocolHeader_t 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] */ ProtocolHeaders_t * pxLastHeaders = ( ( ProtocolHeaders_t * ) &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -490,6 +502,10 @@ UBaseType_t uxOptionsLength ) { /* Map the buffer onto the ProtocolHeader_t 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] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); TCPHeader_t * pxTCPHeader = &pxProtocolHeaders->xTCPHeader; @@ -692,6 +708,10 @@ NetworkBufferDescriptor_t ** ppxNetworkBuffer ) { /* Map the buffer onto the ProtocolHeader_t 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] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); TCPHeader_t * pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); @@ -891,6 +911,10 @@ NetworkBufferDescriptor_t * pxNetworkBuffer ) { /* Map the ethernet buffer onto a TCPPacket_t 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] */ const TCPPacket_t * pxTCPPacket = ( ( const TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); FreeRTOS_Socket_t * pxReturn = NULL; uint32_t ulInitialSequenceNumber; @@ -967,6 +991,10 @@ if( ( ulInitialSequenceNumber != 0U ) && ( pxReturn != NULL ) ) { /* Map the byte stream onto the ProtocolHeaders_t 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] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index 6e3678925..f36b6ac96 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -152,6 +152,10 @@ * now, proceed to send the packet with the SYN flag. * prvTCPPrepareConnect() prepares 'xPacket' and returns pdTRUE if * the Ethernet address of the peer or the gateway is found. */ + + /* 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] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) ); /* About to send a SYN packet. Call prvSetSynAckOptions() to set @@ -304,6 +308,10 @@ #endif { /* Map the ethernet buffer onto a TCPPacket_t 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] */ pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); pxIPHeader = &pxTCPPacket->xIPHeader; pxEthernetHeader = &pxTCPPacket->xEthernetHeader; @@ -662,6 +670,10 @@ /* The MAC-address of the peer (or gateway) has been found, * now prepare the initial TCP packet and some fields in the socket. Map * the buffer onto the TCPPacket_t struct to easily access it's field. */ + + /* 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] */ pxTCPPacket = ( ( TCPPacket_t * ) pxSocket->u.xTCP.xPacket.u.ucLastPacket ); pxIPHeader = &pxTCPPacket->xIPHeader; @@ -960,6 +972,10 @@ } /* Map the ethernet buffer onto the ProtocolHeader_t 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] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow ); lDataLen = 0; @@ -990,6 +1006,10 @@ /* Map the byte stream onto ProtocolHeaders_t 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] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); pucSendData = &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ] ); @@ -1190,6 +1210,10 @@ const NetworkBufferDescriptor_t * pxNetworkBuffer ) { /* Map the ethernet buffer onto the ProtocolHeader_t 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] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); TCPHeader_t * pxTCPHeader = &pxProtocolHeaders->xTCPHeader; @@ -1276,6 +1300,10 @@ BaseType_t xByteCount ) { /* Map the buffer onto the ProtocolHeader_t 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] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); const TCPHeader_t * pxTCPHeader = &pxProtocolHeaders->xTCPHeader; @@ -1429,6 +1457,10 @@ #else { /* Map the ethernet buffer onto the TCPPacket_t 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] */ TCPPacket_t * pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); const uint32_t ulSendLength = ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */ diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index 7f6be59cd..0c5571d6d 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -390,6 +390,10 @@ /* Insert a new list item into pxList, it does not sort the list, * but it puts the item just before xListEnd, so it will be the last item * returned by listGET_HEAD_ENTRY() */ + + /* 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] */ pxNewListItem->pxNext = ( ( ListItem_t * ) pxWhere ); pxNewListItem->pxPrevious = pxWhere->pxPrevious; @@ -478,6 +482,10 @@ /* Find a segment with a given sequence number in the list of received * segments. */ + + /* 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] */ pxEnd = ( ( const ListItem_t * ) &( pxWindow->xRxSegments.xListEnd ) ); for( pxIterator = listGET_NEXT( pxEnd ); @@ -920,6 +928,10 @@ TCPSegment_t * pxBest = NULL; const ListItem_t * pxIterator; uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength; + + /* 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 ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xRxSegments.xListEnd ) ); TCPSegment_t * pxSegment; @@ -1929,6 +1941,10 @@ uint32_t ulSequenceNumber = ulFirst; uint32_t ulDataLength; const ListItem_t * pxIterator; + + /* 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 ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xTxSegments.xListEnd ) ); BaseType_t xDoUnlink; TCPSegment_t * pxSegment; @@ -2081,6 +2097,9 @@ /* A higher Tx block has been acknowledged. Now iterate through the * xWaitQueue to find a possible condition for a FAST retransmission. */ + /* 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] */ pxEnd = ( ( const ListItem_t * ) &( pxWindow->xWaitQueue.xListEnd ) ); pxIterator = listGET_NEXT( pxEnd ); diff --git a/source/FreeRTOS_UDP_IP.c b/source/FreeRTOS_UDP_IP.c index d07dbe6a3..4379c9e27 100644 --- a/source/FreeRTOS_UDP_IP.c +++ b/source/FreeRTOS_UDP_IP.c @@ -103,6 +103,10 @@ void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuff void * pvCopyDest; /* Map the UDP packet onto the start of the frame. */ + + /* 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] */ pxUDPPacket = ( ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); #if ipconfigSUPPORT_OUTGOING_PINGS == 1 @@ -311,6 +315,10 @@ BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffe configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); /* Map the ethernet buffer to the UDPPacket_t 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] */ const UDPPacket_t * pxUDPPacket = ( ( const UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); /* Caller must check for minimum packet size. */ From 4891728ac57bbfa6405deb9c5ebde26811d15221 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Wed, 22 Jun 2022 18:54:20 -0700 Subject: [PATCH 02/12] Added two MISRA deviations --- tools/coverity_misra.config | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/coverity_misra.config b/tools/coverity_misra.config index 7a6c008d7..a90065198 100644 --- a/tools/coverity_misra.config +++ b/tools/coverity_misra.config @@ -10,5 +10,13 @@ deviation: "Rule 3.1", reason: "We post links which contain // inside comments blocks" } + { + deviation: "Directive 4.5", + reason: "Allow names that MISRA considers ambiguous (such as FreeRTOS_ntohl and FreeRTOS_htonl)." + }, + { + deviation: "Rule 20.1", + reason: "#includes are used to include compiler specific attributes to make (packed structures)" + } ] } From d4b0c4a0a9c378ef06e457618be0b41cf36b9ad0 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Tue, 28 Jun 2022 15:11:49 -0700 Subject: [PATCH 03/12] MISRA Rule 11.4 inline suppression --- source/FreeRTOS_DHCP.c | 3 +++ source/FreeRTOS_IP_Utils.c | 5 +++++ source/FreeRTOS_Sockets.c | 30 ++++++++++++++++++++++++++++ source/FreeRTOS_TCP_State_Handling.c | 3 +++ 4 files changed, 41 insertions(+) diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index 58d2af12c..a0ac5e501 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -616,6 +616,9 @@ { xDHCPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* 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 diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 9c38b3958..61e014376 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -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 @@ -833,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 ); /* diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 2424f4ac2..384d4afdd 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -233,6 +233,9 @@ static BaseType_t prvValidSocket( const FreeRTOS_Socket_t * pxSocket, { BaseType_t xReturn; + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ if( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) { xReturn = pdFALSE; @@ -400,6 +403,9 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, if( prvDetermineSocketSize( xDomain, xType, xProtocolCpy, &uxSocketSize ) == pdFAIL ) { + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ xReturn = FREERTOS_INVALID_SOCKET; } else @@ -412,6 +418,9 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, if( pxSocket == NULL ) { + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ xReturn = FREERTOS_INVALID_SOCKET; iptraceFAILED_TO_CREATE_SOCKET(); } @@ -422,6 +431,10 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, if( xEventGroup == NULL ) { vPortFreeSocket( pxSocket ); + + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ xReturn = FREERTOS_INVALID_SOCKET; iptraceFAILED_TO_CREATE_EVENT_GROUP(); } @@ -1226,6 +1239,9 @@ BaseType_t FreeRTOS_bind( Socket_t xSocket, configASSERT( xIsCallingFromIPTask() == pdFALSE ); + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ if( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) { xReturn = -pdFREERTOS_ERRNO_EINVAL; @@ -1457,6 +1473,9 @@ BaseType_t FreeRTOS_closesocket( Socket_t xSocket ) xCloseEvent.eEventType = eSocketCloseEvent; xCloseEvent.pvData = xSocket; + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ if( ( xSocket == NULL ) || ( xSocket == FREERTOS_INVALID_SOCKET ) ) { xResult = 0; @@ -1776,6 +1795,9 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, ( void ) lLevel; ( void ) uxOptionLength; + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ if( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) { xReturn = -pdFREERTOS_ERRNO_EINVAL; @@ -3132,12 +3154,20 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdTRUE ) == pdFALSE ) { /* Not a valid socket or wrong type */ + + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ pxClientSocket = FREERTOS_INVALID_SOCKET; } else if( ( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED ) && ( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eTCP_LISTEN ) ) { /* Parent socket is not in listening mode */ + + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ pxClientSocket = FREERTOS_INVALID_SOCKET; } else diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 50d1d392d..27ca4bb3e 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -967,6 +967,9 @@ FreeRTOS_Socket_t * pxNewSocket = ( FreeRTOS_Socket_t * ) FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); + /* MISRA Rule 11.4 warns about casting pointer to a different type. + * The casting here is to use pointer to pass error code. It is intentional. */ + /* coverity[misra_c_2012_rule_11_4_violation] */ if( ( pxNewSocket == NULL ) || ( pxNewSocket == FREERTOS_INVALID_SOCKET ) ) { FreeRTOS_debug_printf( ( "TCP: Listen: new socket failed\n" ) ); From b4f81e9c7b1c67ac8908a6e34ad3faf6cca5088a Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Tue, 28 Jun 2022 15:30:03 -0700 Subject: [PATCH 04/12] Update wording for rule supression reason. --- source/FreeRTOS_ARP.c | 8 ++++++-- source/FreeRTOS_DNS.c | 12 +++++++++--- source/FreeRTOS_IP.c | 8 ++++++-- source/FreeRTOS_IP_Utils.c | 8 ++++++-- source/FreeRTOS_Sockets.c | 20 +++++++++++++++----- source/FreeRTOS_TCP_IP.c | 8 ++++++-- source/FreeRTOS_TCP_Reception.c | 16 ++++++++++++---- source/FreeRTOS_TCP_State_Handling.c | 20 +++++++++++++++----- source/FreeRTOS_TCP_Transmission.c | 12 +++++++++--- source/FreeRTOS_TCP_WIN.c | 4 +++- 10 files changed, 87 insertions(+), 29 deletions(-) diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 2a499ee52..56e1a41aa 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -329,7 +329,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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ IPPacket_t * pxARPWaitingIPPacket = ( ( IPPacket_t * ) pxARPWaitingNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxARPWaitingIPHeader = &( pxARPWaitingIPPacket->xIPHeader ); @@ -1153,7 +1155,9 @@ void FreeRTOS_ClearARP( void ) 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxUseDescriptor->pucEthernetBuffer ); diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 901ed767e..03caf5f0a 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -423,7 +423,9 @@ 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const DNSMessage_t * pxDNSMessageHeader = ( ( const DNSMessage_t * ) @@ -674,7 +676,9 @@ * 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSMessageHeader = ( ( DNSMessage_t * ) pucUDPPayloadBuffer ); pxDNSMessageHeader->usIdentifier = ( uint16_t ) uxIdentifier; @@ -719,7 +723,9 @@ * 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxTail = ( ( DNSTail_t * ) &( pucUDPPayloadBuffer[ uxStart + 1U ] ) ); diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index a9dbf356e..6d7fa81e8 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1231,7 +1231,9 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor /* 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEthernetHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); @@ -1973,7 +1975,9 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, /* 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEthernetHeader = ( ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 9c38b3958..5b1fd5870 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -463,7 +463,9 @@ 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer ); @@ -508,7 +510,9 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer, * 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtPack = ( ( ProtocolPacket_t * ) &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 2424f4ac2..0b0af8f8f 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -1631,7 +1631,9 @@ void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) const ListItem_t * pxIterator; /* 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); FreeRTOS_Socket_t * pxOtherSocket; @@ -2210,7 +2212,9 @@ static const ListItem_t * pxListFindListItemWithValue( const List_t * pxList, const ListItem_t * pxIterator; /* 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxList->xListEnd ) ); @@ -3916,12 +3920,16 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) TickType_t xDelta = xNow - xLastTime; /* 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); /* 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxIterator = ( const ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); @@ -4020,7 +4028,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) FreeRTOS_Socket_t * pxResult = NULL, * pxListenSocket = 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 4d31dd488..772743fb4 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -542,7 +542,9 @@ /* Map the buffer onto a ProtocolHeaders_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); @@ -800,7 +802,9 @@ BaseType_t xResult = 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEndTCP = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); diff --git a/source/FreeRTOS_TCP_Reception.c b/source/FreeRTOS_TCP_Reception.c index cf57575b5..472c362c5 100644 --- a/source/FreeRTOS_TCP_Reception.c +++ b/source/FreeRTOS_TCP_Reception.c @@ -99,7 +99,9 @@ size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ); /* 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) ); @@ -430,7 +432,9 @@ /* Map the ethernet buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); @@ -440,7 +444,9 @@ /* Map the buffer onto an IPHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const IPHeader_t * pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); const size_t xIPHeaderLength = ipSIZE_OF_IPv4_HEADER; @@ -524,7 +530,9 @@ /* Map the ethernet buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 50d1d392d..481344fb2 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -241,7 +241,9 @@ /* Map the ethernet buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); @@ -356,7 +358,9 @@ /* Map the ethernet buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -504,7 +508,9 @@ /* Map the buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -710,7 +716,9 @@ /* Map the buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); @@ -913,7 +921,9 @@ /* Map the ethernet buffer onto a TCPPacket_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const TCPPacket_t * pxTCPPacket = ( ( const TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); FreeRTOS_Socket_t * pxReturn = NULL; diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index e662e8702..740acde8d 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -974,7 +974,9 @@ /* Map the ethernet buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow ); @@ -1212,7 +1214,9 @@ /* Map the ethernet buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); @@ -1302,7 +1306,9 @@ /* Map the buffer onto the ProtocolHeader_t 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index 0c5571d6d..821e6c9c1 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -392,7 +392,9 @@ * returned by listGET_HEAD_ENTRY() */ /* 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. */ + * The casting is used to map the databuffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxNewListItem->pxNext = ( ( ListItem_t * ) pxWhere ); From 56244bc0ec9f8832268983dcf1ae1cafb7b1d5a6 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Tue, 28 Jun 2022 15:48:43 -0700 Subject: [PATCH 05/12] Fix spell check error --- source/FreeRTOS_ARP.c | 4 ++-- source/FreeRTOS_DNS.c | 6 +++--- source/FreeRTOS_IP.c | 4 ++-- source/FreeRTOS_IP_Utils.c | 4 ++-- source/FreeRTOS_Sockets.c | 10 +++++----- source/FreeRTOS_TCP_IP.c | 4 ++-- source/FreeRTOS_TCP_Reception.c | 8 ++++---- source/FreeRTOS_TCP_State_Handling.c | 10 +++++----- source/FreeRTOS_TCP_Transmission.c | 6 +++--- source/FreeRTOS_TCP_WIN.c | 2 +- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 56e1a41aa..aae16f01a 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -329,7 +329,7 @@ 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. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -1155,7 +1155,7 @@ void FreeRTOS_ClearARP( void ) NetworkBufferDescriptor_t * pxUseDescriptor = pxDescriptor; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 8deb2408a..e1be9ca32 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -427,7 +427,7 @@ BaseType_t xExpected; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -680,7 +680,7 @@ * to easily access fields of the DNS Message. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -727,7 +727,7 @@ * access the fields of the DNS Message. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 6d7fa81e8..7e3bec0eb 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1231,7 +1231,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor /* 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. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -1975,7 +1975,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, /* 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. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 5b1fd5870..82c5e4677 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -463,7 +463,7 @@ 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. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -510,7 +510,7 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer, * of this calculation. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 0b0af8f8f..2fbe40e19 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -1631,7 +1631,7 @@ void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) const ListItem_t * pxIterator; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -2212,7 +2212,7 @@ static const ListItem_t * pxListFindListItemWithValue( const List_t * pxList, const ListItem_t * pxIterator; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -3920,14 +3920,14 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) TickType_t xDelta = xNow - xLastTime; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -4028,7 +4028,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) FreeRTOS_Socket_t * pxResult = NULL, * pxListenSocket = NULL; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 772743fb4..0668e6ff9 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -542,7 +542,7 @@ /* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -802,7 +802,7 @@ BaseType_t xResult = pdFALSE; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_TCP_Reception.c b/source/FreeRTOS_TCP_Reception.c index 472c362c5..cbe68f9f1 100644 --- a/source/FreeRTOS_TCP_Reception.c +++ b/source/FreeRTOS_TCP_Reception.c @@ -99,7 +99,7 @@ size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ); /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -432,7 +432,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -444,7 +444,7 @@ /* Map the buffer onto an IPHeader_t struct for easy access to fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -530,7 +530,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 481344fb2..4933857e3 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -241,7 +241,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -358,7 +358,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -508,7 +508,7 @@ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -716,7 +716,7 @@ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -921,7 +921,7 @@ /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index 740acde8d..22c09b500 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -974,7 +974,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -1214,7 +1214,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ @@ -1306,7 +1306,7 @@ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index 821e6c9c1..f30e3cf29 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -392,7 +392,7 @@ * returned by listGET_HEAD_ENTRY() */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the databuffer to a predefined data structure + * The casting is used to map the data buffer to a predefined data structure * so that the data can be easily accessed. The buffer length has been validated to be * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ From c756a1d93c613caae615cf9a5e1ec695824c35fb Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Fri, 1 Jul 2022 11:52:56 -0700 Subject: [PATCH 06/12] Update Misra deviation comments --- source/FreeRTOS_ARP.c | 8 ++++++-- source/FreeRTOS_DHCP.c | 8 ++++++-- source/FreeRTOS_DNS_Parser.c | 12 +++++++++--- source/FreeRTOS_ICMP.c | 4 +++- source/FreeRTOS_IP.c | 24 ++++++++++++++++++------ source/FreeRTOS_Sockets.c | 8 ++++++-- source/FreeRTOS_TCP_IP.c | 4 +++- source/FreeRTOS_TCP_State_Handling.c | 8 ++++++-- source/FreeRTOS_TCP_Transmission.c | 20 +++++++++++++++----- source/FreeRTOS_TCP_WIN.c | 16 ++++++++++++---- source/FreeRTOS_UDP_IP.c | 8 ++++++-- 11 files changed, 90 insertions(+), 30 deletions(-) diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index aae16f01a..8972fa4fe 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -408,7 +408,9 @@ BaseType_t xCheckRequiresARPResolution( NetworkBufferDescriptor_t * pxNetworkBuf 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); @@ -1081,7 +1083,9 @@ void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffe 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxARPPacket = ( ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index 58d2af12c..745c2a5b0 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -734,7 +734,9 @@ /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayload ); @@ -1017,7 +1019,9 @@ 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayloadBuffer ); diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index cc34fada2..13c5a6f76 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -288,7 +288,9 @@ * 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSMessageHeader = ( ( DNSMessage_t * ) pucUDPPayloadBuffer ); @@ -615,7 +617,9 @@ * 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucBuffer ); @@ -693,7 +697,9 @@ /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucBuffer ); diff --git a/source/FreeRTOS_ICMP.c b/source/FreeRTOS_ICMP.c index e6a6dff92..07e8170e4 100644 --- a/source/FreeRTOS_ICMP.c +++ b/source/FreeRTOS_ICMP.c @@ -93,7 +93,9 @@ * 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ICMPPacket_t * pxICMPPacket = ( ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 7e3bec0eb..8a4d23a72 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1157,7 +1157,9 @@ eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucE /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEthernetHeader = ( ( const EthernetHeader_t * ) pucEthernetBuffer ); @@ -1251,7 +1253,9 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ eReturned = eARPProcessPacket( ( ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ) ); } @@ -1268,7 +1272,9 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ eReturned = prvProcessIPPacket( ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer ); } @@ -1530,7 +1536,9 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtPack = ( ( ProtocolPacket_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); @@ -1687,7 +1695,9 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket, * 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const UDPPacket_t * pxUDPPacket = ( ( const UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); uint16_t usLength; @@ -1822,7 +1832,9 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket, * 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer ); diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 2fbe40e19..d0edd5f44 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -4855,7 +4855,9 @@ BaseType_t xSocketValid( Socket_t xSocket ) if( xRound == 0 ) { /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( xBoundUDPSocketsList.xListEnd ) ); } @@ -4864,7 +4866,9 @@ BaseType_t xSocketValid( Socket_t xSocket ) else { /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); } diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 0668e6ff9..adbb02bbf 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -570,7 +570,9 @@ /* Map the ethernet buffer onto the IPHeader_t 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress ); diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 4933857e3..473fbbb0a 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -414,7 +414,9 @@ /* Map the Last packet onto the ProtocolHeader_t 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxLastHeaders = ( ( ProtocolHeaders_t * ) &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -1003,7 +1005,9 @@ /* Map the byte stream onto the ProtocolHeaders_t 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index 22c09b500..d92ece131 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -154,7 +154,9 @@ * the Ethernet address of the peer or the gateway is found. */ /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) ); @@ -310,7 +312,9 @@ /* Map the ethernet buffer onto a TCPPacket_t 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); pxIPHeader = &pxTCPPacket->xIPHeader; @@ -672,7 +676,9 @@ * the buffer onto the TCPPacket_t struct to easily access it's field. */ /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxTCPPacket = ( ( TCPPacket_t * ) pxSocket->u.xTCP.xPacket.u.ucLastPacket ); pxIPHeader = &pxTCPPacket->xIPHeader; @@ -1010,7 +1016,9 @@ * 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -1464,7 +1472,9 @@ /* Map the ethernet buffer onto the TCPPacket_t 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ TCPPacket_t * pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); const uint32_t ulSendLength = diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index f30e3cf29..f6696d434 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -486,7 +486,9 @@ * segments. */ /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( pxWindow->xRxSegments.xListEnd ) ); @@ -932,7 +934,9 @@ uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength; /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xRxSegments.xListEnd ) ); TCPSegment_t * pxSegment; @@ -1945,7 +1949,9 @@ const ListItem_t * pxIterator; /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xTxSegments.xListEnd ) ); BaseType_t xDoUnlink; @@ -2100,7 +2106,9 @@ * xWaitQueue to find a possible condition for a FAST retransmission. */ /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( pxWindow->xWaitQueue.xListEnd ) ); diff --git a/source/FreeRTOS_UDP_IP.c b/source/FreeRTOS_UDP_IP.c index 4379c9e27..bbf12f598 100644 --- a/source/FreeRTOS_UDP_IP.c +++ b/source/FreeRTOS_UDP_IP.c @@ -105,7 +105,9 @@ void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuff /* Map the UDP packet onto the start of the frame. */ /* 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxUDPPacket = ( ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); @@ -317,7 +319,9 @@ BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffe /* Map the ethernet buffer to the UDPPacket_t 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. */ + * The casting is used to map the data buffer to a predefined data structure + * so that the data can be easily accessed. The buffer length has been validated to be + * at least as big as the size of the data structure to be casted to. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const UDPPacket_t * pxUDPPacket = ( ( const UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); From e58a16ab90696ace6c7c6acb749a2a1f079fe319 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Sat, 2 Jul 2022 16:51:13 -0700 Subject: [PATCH 07/12] Misra violation fix 4.6 11.4 --- source/FreeRTOS_DHCP.c | 4 ++- source/FreeRTOS_DNS_Cache.c | 2 +- source/FreeRTOS_IP_Utils.c | 2 +- source/FreeRTOS_Sockets.c | 36 ++++++++++++++++------ source/FreeRTOS_TCP_State_Handling.c | 4 ++- test/Coverity/CMakeLists.txt | 2 +- test/Coverity/ConfigFiles/FreeRTOSConfig.h | 4 +-- test/Coverity/ConfigFiles/portmacro.h | 4 +-- test/Coverity/Portable.c | 2 +- tools/coverity_misra.config | 10 +++++- 10 files changed, 50 insertions(+), 20 deletions(-) diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index a0ac5e501..678c90832 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -617,7 +617,9 @@ xDHCPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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 ) { diff --git a/source/FreeRTOS_DNS_Cache.c b/source/FreeRTOS_DNS_Cache.c index dc570bbaf..31fc4b3ac 100644 --- a/source/FreeRTOS_DNS_Cache.c +++ b/source/FreeRTOS_DNS_Cache.c @@ -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 */ diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 61e014376..25086cd8d 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -1122,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; } diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 384d4afdd..f41c7ad6c 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -234,7 +234,9 @@ static BaseType_t prvValidSocket( const FreeRTOS_Socket_t * pxSocket, BaseType_t xReturn; /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) { @@ -404,7 +406,9 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, if( prvDetermineSocketSize( xDomain, xType, xProtocolCpy, &uxSocketSize ) == pdFAIL ) { /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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] */ xReturn = FREERTOS_INVALID_SOCKET; } @@ -419,7 +423,9 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, if( pxSocket == NULL ) { /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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] */ xReturn = FREERTOS_INVALID_SOCKET; iptraceFAILED_TO_CREATE_SOCKET(); @@ -433,7 +439,9 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, vPortFreeSocket( pxSocket ); /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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] */ xReturn = FREERTOS_INVALID_SOCKET; iptraceFAILED_TO_CREATE_EVENT_GROUP(); @@ -1240,7 +1248,9 @@ BaseType_t FreeRTOS_bind( Socket_t xSocket, configASSERT( xIsCallingFromIPTask() == pdFALSE ); /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) { @@ -1474,7 +1484,9 @@ BaseType_t FreeRTOS_closesocket( Socket_t xSocket ) xCloseEvent.pvData = xSocket; /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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( ( xSocket == NULL ) || ( xSocket == FREERTOS_INVALID_SOCKET ) ) { @@ -1796,7 +1808,9 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, ( void ) uxOptionLength; /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) { @@ -3156,7 +3170,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) /* Not a valid socket or wrong type */ /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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] */ pxClientSocket = FREERTOS_INVALID_SOCKET; } @@ -3166,7 +3182,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) /* Parent socket is not in listening mode */ /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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] */ pxClientSocket = FREERTOS_INVALID_SOCKET; } diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 27ca4bb3e..4249b1c45 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -968,7 +968,9 @@ FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. It is intentional. */ + * 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( ( pxNewSocket == NULL ) || ( pxNewSocket == FREERTOS_INVALID_SOCKET ) ) { diff --git a/test/Coverity/CMakeLists.txt b/test/Coverity/CMakeLists.txt index b328655e8..ce55c3d9e 100644 --- a/test/Coverity/CMakeLists.txt +++ b/test/Coverity/CMakeLists.txt @@ -58,4 +58,4 @@ target_include_directories( StaticAnalysis PUBLIC "${MODULE_ROOT_DIR}/source/include" ) # Uncomment the below line if the desired platform is 32-bit -# set_target_properties( StaticAnalysis PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" ) +set_target_properties( StaticAnalysis PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" ) diff --git a/test/Coverity/ConfigFiles/FreeRTOSConfig.h b/test/Coverity/ConfigFiles/FreeRTOSConfig.h index 435adb4da..10ad4937c 100644 --- a/test/Coverity/ConfigFiles/FreeRTOSConfig.h +++ b/test/Coverity/ConfigFiles/FreeRTOSConfig.h @@ -46,7 +46,7 @@ #define configUSE_TICK_HOOK 1 #define configUSE_DAEMON_TASK_STARTUP_HOOK 1 #define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ -#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ +#define configMINIMAL_STACK_SIZE ( 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) ) #define configMAX_TASK_NAME_LEN ( 12 ) #define configUSE_TRACE_FACILITY 1 @@ -74,7 +74,7 @@ #define configMAX_PRIORITIES ( 7 ) /* Run time stats gathering configuration options. */ -unsigned long ulGetRunTimeCounterValue( void ); /* Prototype of function that returns run time counter. */ +uint32_t ulGetRunTimeCounterValue( void ); /* Prototype of function that returns run time counter. */ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */ #define configGENERATE_RUN_TIME_STATS 1 #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats() diff --git a/test/Coverity/ConfigFiles/portmacro.h b/test/Coverity/ConfigFiles/portmacro.h index 104d8e240..fd931d94c 100644 --- a/test/Coverity/ConfigFiles/portmacro.h +++ b/test/Coverity/ConfigFiles/portmacro.h @@ -42,8 +42,8 @@ #define portPOINTER_SIZE_TYPE size_t typedef portSTACK_TYPE StackType_t; -typedef long BaseType_t; -typedef unsigned long UBaseType_t; +typedef int32_t BaseType_t; +typedef uint32_t UBaseType_t; #if ( configUSE_16_BIT_TICKS == 1 ) diff --git a/test/Coverity/Portable.c b/test/Coverity/Portable.c index d35ae29ad..0cae0b0d5 100644 --- a/test/Coverity/Portable.c +++ b/test/Coverity/Portable.c @@ -56,7 +56,7 @@ void vApplicationIdleHook( void ) void vApplicationTickHook( void ) { } -unsigned long ulGetRunTimeCounterValue( void ) +uint32_t ulGetRunTimeCounterValue( void ) { } void vPortEndScheduler( void ) diff --git a/tools/coverity_misra.config b/tools/coverity_misra.config index a90065198..d8be2f98f 100644 --- a/tools/coverity_misra.config +++ b/tools/coverity_misra.config @@ -9,11 +9,19 @@ { deviation: "Rule 3.1", reason: "We post links which contain // inside comments blocks" - } + }, { deviation: "Directive 4.5", reason: "Allow names that MISRA considers ambiguous (such as FreeRTOS_ntohl and FreeRTOS_htonl)." }, + { + deviation: "Rule 8.7", + reason: "Functions are interfaces to be called by application modules." + }, + { + deviation: "Rule 19.2", + reason: "Unions are used to reduce the memory footprint." + }, { deviation: "Rule 20.1", reason: "#includes are used to include compiler specific attributes to make (packed structures)" From 77165f3f9e10eee078a75f3af10ebfae889409dd Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Thu, 7 Jul 2022 13:42:13 -0700 Subject: [PATCH 08/12] Misra rule 1.2 suppression --- test/Coverity/ConfigFiles/pack_struct_end.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Coverity/ConfigFiles/pack_struct_end.h b/test/Coverity/ConfigFiles/pack_struct_end.h index b9609c56e..3753e2ab3 100644 --- a/test/Coverity/ConfigFiles/pack_struct_end.h +++ b/test/Coverity/ConfigFiles/pack_struct_end.h @@ -34,4 +34,6 @@ /* Keyword required to appear after any structure which has packed * placement in memory. */ +/* The language extension is used in a portable manner for each specific compiler +/* coverity[misra_c_2012_rule_1_2_violation]*/ __attribute__( ( packed ) ); From da9d4b624738869eb7045728eb646452e15a7022 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Thu, 7 Jul 2022 14:17:54 -0700 Subject: [PATCH 09/12] Fix format check failures --- test/Coverity/ConfigFiles/FreeRTOSConfig.h | 4 ++-- test/Coverity/ConfigFiles/pack_struct_end.h | 5 +++-- test/Coverity/ConfigFiles/portmacro.h | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/Coverity/ConfigFiles/FreeRTOSConfig.h b/test/Coverity/ConfigFiles/FreeRTOSConfig.h index e32cb54e3..0ed7542f3 100644 --- a/test/Coverity/ConfigFiles/FreeRTOSConfig.h +++ b/test/Coverity/ConfigFiles/FreeRTOSConfig.h @@ -74,8 +74,8 @@ #define configMAX_PRIORITIES ( 7 ) /* Run time stats gathering configuration options. */ -uint32_t ulGetRunTimeCounterValue( void ); /* Prototype of function that returns run time counter. */ -void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */ +uint32_t ulGetRunTimeCounterValue( void ); /* Prototype of function that returns run time counter. */ +void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */ #define configGENERATE_RUN_TIME_STATS 1 #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats() #define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue() diff --git a/test/Coverity/ConfigFiles/pack_struct_end.h b/test/Coverity/ConfigFiles/pack_struct_end.h index 3753e2ab3..fc5e3e561 100644 --- a/test/Coverity/ConfigFiles/pack_struct_end.h +++ b/test/Coverity/ConfigFiles/pack_struct_end.h @@ -34,6 +34,7 @@ /* Keyword required to appear after any structure which has packed * placement in memory. */ -/* The language extension is used in a portable manner for each specific compiler -/* coverity[misra_c_2012_rule_1_2_violation]*/ + +/* The language extension is used in a portable manner for each specific compiler */ + * /* coverity[misra_c_2012_rule_1_2_violation]*/ __attribute__( ( packed ) ); diff --git a/test/Coverity/ConfigFiles/portmacro.h b/test/Coverity/ConfigFiles/portmacro.h index fd931d94c..61382d6cb 100644 --- a/test/Coverity/ConfigFiles/portmacro.h +++ b/test/Coverity/ConfigFiles/portmacro.h @@ -42,8 +42,8 @@ #define portPOINTER_SIZE_TYPE size_t typedef portSTACK_TYPE StackType_t; -typedef int32_t BaseType_t; -typedef uint32_t UBaseType_t; +typedef int32_t BaseType_t; +typedef uint32_t UBaseType_t; #if ( configUSE_16_BIT_TICKS == 1 ) From 8a9db1c5c5a48ed2ff4339497c92e0d8e1d40993 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Thu, 7 Jul 2022 14:39:36 -0700 Subject: [PATCH 10/12] Fix format check failure --- test/Coverity/ConfigFiles/pack_struct_end.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Coverity/ConfigFiles/pack_struct_end.h b/test/Coverity/ConfigFiles/pack_struct_end.h index fc5e3e561..91eb56854 100644 --- a/test/Coverity/ConfigFiles/pack_struct_end.h +++ b/test/Coverity/ConfigFiles/pack_struct_end.h @@ -36,5 +36,5 @@ * placement in memory. */ /* The language extension is used in a portable manner for each specific compiler */ - * /* coverity[misra_c_2012_rule_1_2_violation]*/ +/* coverity[misra_c_2012_rule_1_2_violation]*/ __attribute__( ( packed ) ); From 144a5d52e56438cbec5e955b3b85c644cdcada02 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Thu, 7 Jul 2022 16:27:47 -0700 Subject: [PATCH 11/12] Update rule 11.3 reason --- source/FreeRTOS_ARP.c | 16 ++++--------- source/FreeRTOS_DHCP.c | 10 ++------ source/FreeRTOS_DNS.c | 12 +++------- source/FreeRTOS_DNS_Parser.c | 13 +++-------- source/FreeRTOS_ICMP.c | 5 +--- source/FreeRTOS_IP.c | 34 +++++++--------------------- source/FreeRTOS_IP_Utils.c | 8 ++----- source/FreeRTOS_Sockets.c | 28 ++++++----------------- source/FreeRTOS_TCP_IP.c | 13 +++-------- source/FreeRTOS_TCP_Reception.c | 16 ++++--------- source/FreeRTOS_TCP_State_Handling.c | 29 ++++++------------------ source/FreeRTOS_TCP_Transmission.c | 34 +++++++--------------------- source/FreeRTOS_TCP_WIN.c | 24 ++++---------------- source/FreeRTOS_UDP_IP.c | 8 ++----- 14 files changed, 59 insertions(+), 191 deletions(-) diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index ed3266f7b..19ecc7ce3 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -329,9 +329,7 @@ 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. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ IPPacket_t * pxARPWaitingIPPacket = ( ( IPPacket_t * ) pxARPWaitingNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxARPWaitingIPHeader = &( pxARPWaitingIPPacket->xIPHeader ); @@ -408,9 +406,7 @@ BaseType_t xCheckRequiresARPResolution( NetworkBufferDescriptor_t * pxNetworkBuf BaseType_t xNeedsARPResolution = pdFALSE; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); @@ -1083,9 +1079,7 @@ void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffe configASSERT( pxNetworkBuffer->xDataLength >= sizeof( ARPPacket_t ) ); /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxARPPacket = ( ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); @@ -1159,9 +1153,7 @@ void FreeRTOS_ClearARP( void ) NetworkBufferDescriptor_t * pxUseDescriptor = pxDescriptor; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxUseDescriptor->pucEthernetBuffer ); diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index 353e3cab9..107ee0db6 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -739,10 +739,7 @@ /* Map a DHCP structure onto the received data. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayload ); /* Sanity check. */ @@ -1024,10 +1021,7 @@ pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ); /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayloadBuffer ); /* Most fields need to be zero. */ diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index fef5b821d..bad2b2a17 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -427,9 +427,7 @@ BaseType_t xExpected; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const DNSMessage_t * pxDNSMessageHeader = ( ( const DNSMessage_t * ) @@ -686,9 +684,7 @@ * to easily access fields of the DNS Message. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSMessageHeader = ( ( DNSMessage_t * ) pucUDPPayloadBuffer ); pxDNSMessageHeader->usIdentifier = ( uint16_t ) uxIdentifier; @@ -733,9 +729,7 @@ * access the fields of the DNS Message. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxTail = ( ( DNSTail_t * ) &( pucUDPPayloadBuffer[ uxStart + 1U ] ) ); diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index fbe66f2b9..756646cd5 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -288,10 +288,7 @@ * for easier access. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSMessageHeader = ( ( DNSMessage_t * ) pucUDPPayloadBuffer ); @@ -617,9 +614,7 @@ * fields of the structure. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucBuffer ); @@ -697,9 +692,7 @@ /* 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. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucBuffer ); diff --git a/source/FreeRTOS_ICMP.c b/source/FreeRTOS_ICMP.c index 94a96405a..937eaf478 100644 --- a/source/FreeRTOS_ICMP.c +++ b/source/FreeRTOS_ICMP.c @@ -93,10 +93,7 @@ * fields of ICMP packet. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ICMPPacket_t * pxICMPPacket = ( ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); switch( pxICMPPacket->xICMPHeader.ucTypeOfMessage ) diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 0d980633d..ba7214fdb 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1164,9 +1164,7 @@ eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucE /* 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. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEthernetHeader = ( ( const EthernetHeader_t * ) pucEthernetBuffer ); @@ -1240,9 +1238,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor /* 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. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEthernetHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); @@ -1260,9 +1256,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor if( pxNetworkBuffer->xDataLength >= sizeof( ARPPacket_t ) ) { /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ eReturned = eARPProcessPacket( ( ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ) ); } @@ -1279,9 +1273,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor if( pxNetworkBuffer->xDataLength >= sizeof( IPPacket_t ) ) { /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ eReturned = prvProcessIPPacket( ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer ); } @@ -1543,10 +1535,7 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP /* 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. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* 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 ) @@ -1702,9 +1691,7 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket, * fields of UDP packet. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const UDPPacket_t * pxUDPPacket = ( ( const UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); uint16_t usLength; @@ -1839,10 +1826,7 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket, * fields of the IP packet. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer ); ucVersionHeaderLength = pxIPPacket->xIPHeader.ucVersionHeaderLength; @@ -1994,9 +1978,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, /* 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. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEthernetHeader = ( ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 87da0b8d0..a2eb4fc15 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -464,9 +464,7 @@ 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. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer ); @@ -511,9 +509,7 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer, * of this calculation. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtPack = ( ( ProtocolPacket_t * ) &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index afca75d7d..d753bbaea 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -1662,9 +1662,7 @@ void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) const ListItem_t * pxIterator; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); FreeRTOS_Socket_t * pxOtherSocket; @@ -2249,9 +2247,7 @@ static const ListItem_t * pxListFindListItemWithValue( const List_t * pxList, const ListItem_t * pxIterator; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxList->xListEnd ) ); @@ -3968,16 +3964,12 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) TickType_t xDelta = xNow - xLastTime; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxIterator = ( const ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); @@ -4076,9 +4068,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) FreeRTOS_Socket_t * pxResult = NULL, * pxListenSocket = NULL; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); @@ -4903,9 +4893,7 @@ BaseType_t xSocketValid( Socket_t xSocket ) if( xRound == 0 ) { /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( xBoundUDPSocketsList.xListEnd ) ); } @@ -4914,9 +4902,7 @@ BaseType_t xSocketValid( Socket_t xSocket ) else { /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); } diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index b12f1117a..9fece2bd9 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -542,9 +542,7 @@ /* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); @@ -570,10 +568,7 @@ /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress ); ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress ); @@ -804,9 +799,7 @@ BaseType_t xResult = pdFALSE; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEndTCP = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); diff --git a/source/FreeRTOS_TCP_Reception.c b/source/FreeRTOS_TCP_Reception.c index 109baeb5b..b44bffe83 100644 --- a/source/FreeRTOS_TCP_Reception.c +++ b/source/FreeRTOS_TCP_Reception.c @@ -99,9 +99,7 @@ size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ); /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) ); @@ -432,9 +430,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); @@ -444,9 +440,7 @@ /* Map the buffer onto an IPHeader_t struct for easy access to fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const IPHeader_t * pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); const size_t xIPHeaderLength = ipSIZE_OF_IPv4_HEADER; @@ -530,9 +524,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 32156ae2e..1397d0d39 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -241,9 +241,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); @@ -358,9 +356,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -414,9 +410,7 @@ /* Map the Last packet onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxLastHeaders = ( ( ProtocolHeaders_t * ) &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -510,9 +504,7 @@ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -718,9 +710,7 @@ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); @@ -923,9 +913,7 @@ /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const TCPPacket_t * pxTCPPacket = ( ( const TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); FreeRTOS_Socket_t * pxReturn = NULL; @@ -1010,10 +998,7 @@ /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index feb9b5f17..38521fcfe 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -154,9 +154,7 @@ * the Ethernet address of the peer or the gateway is found. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) ); @@ -312,10 +310,7 @@ /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); pxIPHeader = &pxTCPPacket->xIPHeader; pxEthernetHeader = &pxTCPPacket->xEthernetHeader; @@ -676,10 +671,7 @@ * the buffer onto the TCPPacket_t struct to easily access it's field. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxTCPPacket = ( ( TCPPacket_t * ) pxSocket->u.xTCP.xPacket.u.ucLastPacket ); pxIPHeader = &pxTCPPacket->xIPHeader; @@ -980,9 +972,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow ); @@ -1016,9 +1006,7 @@ * access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); @@ -1222,9 +1210,7 @@ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); @@ -1314,9 +1300,7 @@ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); @@ -1472,9 +1456,7 @@ /* Map the ethernet buffer onto the TCPPacket_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ TCPPacket_t * pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); const uint32_t ulSendLength = diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index 3f0c24ca4..f13f963de 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -392,9 +392,7 @@ * returned by listGET_HEAD_ENTRY() */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxNewListItem->pxNext = ( ( ListItem_t * ) pxWhere ); @@ -486,10 +484,7 @@ * segments. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( pxWindow->xRxSegments.xListEnd ) ); for( pxIterator = listGET_NEXT( pxEnd ); @@ -934,10 +929,7 @@ uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xRxSegments.xListEnd ) ); TCPSegment_t * pxSegment; @@ -1949,10 +1941,7 @@ const ListItem_t * pxIterator; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xTxSegments.xListEnd ) ); BaseType_t xDoUnlink; TCPSegment_t * pxSegment; @@ -2106,10 +2095,7 @@ * xWaitQueue to find a possible condition for a FAST retransmission. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ - /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( pxWindow->xWaitQueue.xListEnd ) ); pxIterator = listGET_NEXT( pxEnd ); diff --git a/source/FreeRTOS_UDP_IP.c b/source/FreeRTOS_UDP_IP.c index 37df60d42..73f3df3af 100644 --- a/source/FreeRTOS_UDP_IP.c +++ b/source/FreeRTOS_UDP_IP.c @@ -105,9 +105,7 @@ void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuff /* Map the UDP packet onto the start of the frame. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxUDPPacket = ( ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); @@ -319,9 +317,7 @@ BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffe /* Map the ethernet buffer to the UDPPacket_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The casting is used to map the data buffer to a predefined data structure - * so that the data can be easily accessed. The buffer length has been validated to be - * at least as big as the size of the data structure to be casted to. */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ const UDPPacket_t * pxUDPPacket = ( ( const UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); From 39d08ff4203f579c285a24bbdb9e17d9e7a0e237 Mon Sep 17 00:00:00 2001 From: Xueli Xie Date: Mon, 11 Jul 2022 16:47:32 -0700 Subject: [PATCH 12/12] Change rule 11.4 wording. --- source/FreeRTOS_DHCP.c | 10 ++++---- source/FreeRTOS_DNS_Parser.c | 3 ++- source/FreeRTOS_ICMP.c | 3 ++- source/FreeRTOS_IP.c | 6 +++-- source/FreeRTOS_Sockets.c | 36 ++++++++++++++-------------- source/FreeRTOS_TCP_IP.c | 3 ++- source/FreeRTOS_TCP_State_Handling.c | 7 +++--- source/FreeRTOS_TCP_Transmission.c | 6 +++-- source/FreeRTOS_TCP_WIN.c | 12 ++++++---- 9 files changed, 50 insertions(+), 36 deletions(-) diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index 530e17bac..53e5bdd69 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -616,8 +616,8 @@ { xDHCPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -739,7 +739,8 @@ /* Map a DHCP structure onto the received data. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayload ); /* Sanity check. */ @@ -1021,7 +1022,8 @@ pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ); /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayloadBuffer ); /* Most fields need to be zero. */ diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index f102d3a3b..2eb8cd108 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -288,7 +288,8 @@ * for easier access. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSMessageHeader = ( ( DNSMessage_t * ) pucUDPPayloadBuffer ); diff --git a/source/FreeRTOS_ICMP.c b/source/FreeRTOS_ICMP.c index cdb364133..65ea797d0 100644 --- a/source/FreeRTOS_ICMP.c +++ b/source/FreeRTOS_ICMP.c @@ -93,7 +93,8 @@ * fields of ICMP packet. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ ICMPPacket_t * pxICMPPacket = ( ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); switch( pxICMPPacket->xICMPHeader.ucTypeOfMessage ) diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 35c9e2594..098125f46 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1535,7 +1535,8 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP /* 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. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* 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 ) @@ -1829,7 +1830,8 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket, * fields of the IP packet. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer ); ucVersionHeaderLength = pxIPPacket->xIPHeader.ucVersionHeaderLength; diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 67bdbbff6..a79232c2a 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -233,8 +233,8 @@ static BaseType_t prvValidSocket( const FreeRTOS_Socket_t * pxSocket, { BaseType_t xReturn; - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -405,8 +405,8 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, if( prvDetermineSocketSize( xDomain, xType, xProtocolCpy, &uxSocketSize ) == pdFAIL ) { - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -422,8 +422,8 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, if( pxSocket == NULL ) { - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -438,8 +438,8 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, { vPortFreeSocket( pxSocket ); - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -1247,8 +1247,8 @@ BaseType_t FreeRTOS_bind( Socket_t xSocket, configASSERT( xIsCallingFromIPTask() == pdFALSE ); - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -1483,8 +1483,8 @@ BaseType_t FreeRTOS_closesocket( Socket_t xSocket ) xCloseEvent.eEventType = eSocketCloseEvent; xCloseEvent.pvData = xSocket; - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -1807,8 +1807,8 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, ( void ) lLevel; ( void ) uxOptionLength; - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -3169,8 +3169,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) { /* Not a valid socket or wrong type */ - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -3181,8 +3181,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) { /* Parent socket is not in listening mode */ - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 9fece2bd9..aba2a0e81 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -568,7 +568,8 @@ /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress ); ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress ); diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 1397d0d39..1c8fe1f25 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -967,8 +967,8 @@ FreeRTOS_Socket_t * pxNewSocket = ( FreeRTOS_Socket_t * ) FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); - /* MISRA Rule 11.4 warns about casting pointer to a different type. - * The casting here is to use pointer to pass error code. + /* MISRA Rule 11.4 warns about conversion between a pointer and an integer. + * The conversion 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] */ @@ -998,7 +998,8 @@ /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index 38521fcfe..637863c0b 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -310,7 +310,8 @@ /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); pxIPHeader = &pxTCPPacket->xIPHeader; pxEthernetHeader = &pxTCPPacket->xEthernetHeader; @@ -671,7 +672,8 @@ * the buffer onto the TCPPacket_t struct to easily access it's field. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxTCPPacket = ( ( TCPPacket_t * ) pxSocket->u.xTCP.xPacket.u.ucLastPacket ); pxIPHeader = &pxTCPPacket->xIPHeader; diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index b489fc1a8..121d4b0fe 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -484,7 +484,8 @@ * segments. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( pxWindow->xRxSegments.xListEnd ) ); for( pxIterator = listGET_NEXT( pxEnd ); @@ -929,7 +930,8 @@ uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xRxSegments.xListEnd ) ); TCPSegment_t * pxSegment; @@ -1941,7 +1943,8 @@ const ListItem_t * pxIterator; /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xTxSegments.xListEnd ) ); BaseType_t xDoUnlink; TCPSegment_t * pxSegment; @@ -2095,7 +2098,8 @@ * xWaitQueue to find a possible condition for a FAST retransmission. */ /* MISRA C-2012 Rule 11.3 warns about casting pointer type to a different data type. - * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ /* coverity[misra_c_2012_rule_11_3_violation] */ + * The struct to be casted to is defined as a packed struct. The cast won't cause misalignment. */ + /* coverity[misra_c_2012_rule_11_3_violation] */ pxEnd = ( ( const ListItem_t * ) &( pxWindow->xWaitQueue.xListEnd ) ); pxIterator = listGET_NEXT( pxEnd );