diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c index 7e7f50492..ad8c28e28 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c @@ -92,11 +92,21 @@ eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame ) eFrameProcessingResult_t eReturn = eReleaseBuffer; ARPHeader_t *pxARPHeader; uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; pxARPHeader = &( pxARPFrame->xARPHeader ); /* The field ulSenderProtocolAddress is badly aligned, copy byte-by-byte. */ - ( void ) memcpy( ( void * ) ( &( ulSenderProtocolAddress ) ), ( const void * ) ( pxARPHeader->ucSenderProtocolAddress ), sizeof( ulSenderProtocolAddress ) ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = pxARPHeader->ucSenderProtocolAddress; + pvCopyDest = &ulSenderProtocolAddress; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( ulSenderProtocolAddress ) ); /* The field ulTargetProtocolAddress is well-aligned, a 32-bits copy. */ ulTargetProtocolAddress = pxARPHeader->ulTargetProtocolAddress; @@ -126,17 +136,41 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress; { /* A double IP address is detected! */ /* Give the sources MAC address the value of the broadcast address, will be swapped later */ - ( void ) memcpy( pxARPFrame->xEthernetHeader.xSourceAddress.ucBytes, xBroadcastMACAddress.ucBytes, sizeof( xBroadcastMACAddress ) ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = xBroadcastMACAddress.ucBytes; + pvCopyDest = pxARPFrame->xEthernetHeader.xSourceAddress.ucBytes; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xBroadcastMACAddress ) ); + ( void ) memset( pxARPHeader->xTargetHardwareAddress.ucBytes, 0, sizeof( MACAddress_t ) ); pxARPHeader->ulTargetProtocolAddress = 0UL; } else { - ( void ) memcpy( pxARPHeader->xTargetHardwareAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( MACAddress_t ) ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = pxARPHeader->xSenderHardwareAddress.ucBytes; + pvCopyDest = pxARPHeader->xTargetHardwareAddress.ucBytes; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( MACAddress_t ) ); pxARPHeader->ulTargetProtocolAddress = ulSenderProtocolAddress; } - ( void ) memcpy( ( void * ) ( pxARPHeader->xSenderHardwareAddress.ucBytes ), ( const void * ) ( ipLOCAL_MAC_ADDRESS ), sizeof( MACAddress_t ) ); - ( void ) memcpy( ( void * ) ( pxARPHeader->ucSenderProtocolAddress ), ( const void * ) ( ipLOCAL_IP_ADDRESS_POINTER ), sizeof( pxARPHeader->ucSenderProtocolAddress ) ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = ipLOCAL_MAC_ADDRESS; + pvCopyDest = pxARPHeader->xSenderHardwareAddress.ucBytes; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( MACAddress_t ) ); + pvCopySource = ipLOCAL_IP_ADDRESS_POINTER; + pvCopyDest = pxARPHeader->ucSenderProtocolAddress; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( pxARPHeader->ucSenderProtocolAddress ) ); eReturn = eReturnEthernetFrame; } @@ -650,6 +684,10 @@ static const uint8_t xDefaultPartARPPacketHeader[] = ARPPacket_t *pxARPPacket; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; + /* Buffer allocation ensures that buffers always have space for an ARP packet. See buffer allocation implementations 1 and 2 under portable/BufferManagement. */ @@ -669,11 +707,26 @@ ARPPacket_t *pxARPPacket; xARPHeader.usOperation; xARPHeader.xTargetHardwareAddress; */ - ( void ) memcpy( ( void * ) pxARPPacket, ( const void * ) xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) ); - ( void ) memcpy( ( void * ) ( pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes ) , ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); - ( void ) memcpy( ( void * ) ( pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes ), ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = xDefaultPartARPPacketHeader; + pvCopyDest = pxARPPacket; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xDefaultPartARPPacketHeader ) ); - ( void ) memcpy( ( void * ) ( pxARPPacket->xARPHeader.ucSenderProtocolAddress ), ( const void * ) ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) ); + pvCopySource = ipLOCAL_MAC_ADDRESS; + pvCopyDest = pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes; + ( void ) memcpy( pvCopyDest, pvCopySource, ipMAC_ADDRESS_LENGTH_BYTES ); + + pvCopySource = ipLOCAL_MAC_ADDRESS; + pvCopyDest = pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes; + ( void ) memcpy( pvCopyDest, pvCopySource, ipMAC_ADDRESS_LENGTH_BYTES ); + + pvCopySource = ipLOCAL_IP_ADDRESS_POINTER; + pvCopyDest = pxARPPacket->xARPHeader.ucSenderProtocolAddress; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) ); pxARPPacket->xARPHeader.ulTargetProtocolAddress = pxNetworkBuffer->ulIPAddress; pxNetworkBuffer->xDataLength = sizeof( ARPPacket_t ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c index c12557e7a..191661354 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c @@ -642,6 +642,9 @@ uint8_t ucOptionCode; uint32_t ulProcessed, ulParameter; BaseType_t xReturn = pdFALSE; const uint32_t ulMandatoryOptions = 2UL; /* DHCP server address, and the correct DHCP message type must be present in the options. */ +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; /* Passing the address of a pointer (pucUDPPayload) because FREERTOS_ZERO_COPY is used. */ lBytes = FreeRTOS_recvfrom( xDHCPSocket, &pucUDPPayload, 0UL, FREERTOS_ZERO_COPY, NULL, NULL ); @@ -726,9 +729,14 @@ const uint32_t ulMandatoryOptions = 2UL; /* DHCP server address, and the correct just get it once here and use later. */ if( uxLength >= sizeof( ulParameter ) ) { - ( void ) memcpy( ( void * ) ( &( ulParameter ) ), - ( const void * ) ( &( pucByte[ uxIndex ] ) ), - ( size_t ) sizeof( ulParameter ) ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = &pucByte[ uxIndex ]; + pvCopyDest = &ulParameter; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( ulParameter ) ); /* 'uxIndex' will be increased at the end of this loop. */ } else @@ -876,6 +884,9 @@ DHCPMessage_IPv4_t *pxDHCPMessage; size_t uxRequiredBufferSize = sizeof( DHCPMessage_IPv4_t ) + *pxOptionsArraySize; const NetworkBufferDescriptor_t *pxNetworkBuffer; uint8_t *pucUDPPayloadBuffer; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; #if( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) const char *pucHostName = pcApplicationHostnameHook (); @@ -931,7 +942,15 @@ uint8_t *pucUDPPayloadBuffer; pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] ); pucPtr[ 0U ] = dhcpIPv4_DNS_HOSTNAME_OPTIONS_CODE; pucPtr[ 1U ] = ( uint8_t ) uxNameLength; - ( void ) memcpy( ( void * ) ( &( pucPtr[ 2U ] ) ), ( const void * ) pucHostName, uxNameLength ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = pucHostName; + pvCopyDest = &pucPtr[ 2U ]; + + ( void ) memcpy( pvCopyDest, pvCopySource, uxNameLength ); pucPtr[ 2U + uxNameLength ] = ( uint8_t ) dhcpOPTION_END_BYTE; *pxOptionsArraySize += ( size_t ) ( 2U + uxNameLength ); } @@ -965,6 +984,9 @@ static const uint8_t ucDHCPRequestOptions[] = dhcpOPTION_END_BYTE }; size_t uxOptionsLength = sizeof( ucDHCPRequestOptions ); +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; pucUDPPayloadBuffer = prvCreatePartDHCPMessage( &xAddress, ( BaseType_t ) dhcpREQUEST_OPCODE, @@ -972,14 +994,19 @@ size_t uxOptionsLength = sizeof( ucDHCPRequestOptions ); &( uxOptionsLength ) ); /* Copy in the IP address being requested. */ - ( void ) memcpy( ( void * ) ( &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpREQUESTED_IP_ADDRESS_OFFSET ] ) ), - ( const void * ) ( &( EP_DHCPData.ulOfferedIPAddress ) ), - sizeof( EP_DHCPData.ulOfferedIPAddress ) ); + /* + * Use helper variables for memcpy() source & dest to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = &EP_DHCPData.ulOfferedIPAddress; + pvCopyDest = &pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpREQUESTED_IP_ADDRESS_OFFSET ]; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( EP_DHCPData.ulOfferedIPAddress ) ); /* Copy in the address of the DHCP server being used. */ - ( void ) memcpy( ( void * ) ( &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ] ) ), - ( const void * ) ( &( EP_DHCPData.ulDHCPServerAddress ) ), - sizeof( EP_DHCPData.ulDHCPServerAddress ) ); + pvCopySource = &EP_DHCPData.ulDHCPServerAddress; + pvCopyDest = &pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ]; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( EP_DHCPData.ulDHCPServerAddress ) ); FreeRTOS_debug_printf( ( "vDHCPProcess: reply %lxip\n", FreeRTOS_ntohl( EP_DHCPData.ulOfferedIPAddress ) ) ); iptraceSENDING_DHCP_REQUEST(); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c index c4d704010..7172f4540 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c @@ -843,10 +843,20 @@ static const DNSMessage_t xDefaultPartDNSHeader = 0, /* No authorities. */ 0 /* No additional authorities. */ }; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; /* Copy in the const part of the header. Intentionally using different * pointers with memcpy() to put the information in to correct place. */ - ( void ) memcpy( ( void * ) pucUDPPayloadBuffer, ( const void * ) ( &( xDefaultPartDNSHeader ) ), sizeof( xDefaultPartDNSHeader ) ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = &xDefaultPartDNSHeader; + pvCopyDest = pucUDPPayloadBuffer; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xDefaultPartDNSHeader ) ); /* Write in a unique identifier. Cast the Payload Buffer to DNSMessage_t * to easily access fields of the DNS Message. */ @@ -1070,7 +1080,7 @@ size_t uxIndex = 0U; /* The function below will only be called : when ipconfigDNS_USE_CALLBACKS == 1 when ipconfigUSE_LLMNR == 1 -for testing purposes, by the module iot_test_freertos_tcp.c +for testing purposes, by the module test_freertos_tcp.c */ uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t *pxNetworkBuffer ) { @@ -1134,6 +1144,9 @@ size_t uxSourceBytesRemaining; uint16_t x, usDataLength, usQuestions; uint16_t usType = 0U; BaseType_t xReturn = pdTRUE; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; #if( ipconfigUSE_LLMNR == 1 ) uint16_t usClass = 0U; @@ -1314,9 +1327,14 @@ BaseType_t xReturn = pdTRUE; { /* Copy the IP address out of the record. Using different pointers * to copy only the portion we want is intentional here. */ - ( void ) memcpy( ( void * ) ( &( ulIPAddress ) ), - ( const void * ) ( &( pucByte[ sizeof( DNSAnswerRecord_t ) ] ) ), - sizeof( uint32_t ) ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = &pucByte[ sizeof( DNSAnswerRecord_t ) ]; + pvCopyDest = &ulIPAddress; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( uint32_t ) ); #if( ipconfigDNS_USE_CALLBACKS == 1 ) { @@ -1656,7 +1674,7 @@ BaseType_t xReturn; /* This must be the first time this function has been called. Create the socket. */ xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); - if( prvSocketValid( xSocket ) != pdTRUE ) + if( prvSocketValid( xSocket ) != pdTRUE_UNSIGNED ) { /* There was an error, return NULL. */ xSocket = NULL; diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c index aa0513d89..8bb9c85a4 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c @@ -844,9 +844,9 @@ TickType_t uxBlockTime = uxBlockTimeTicks; /* Cap the block time. The reason for this is explained where ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined (assuming an official FreeRTOSIPConfig.h header file is being used). */ - if( uxBlockTime > ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ) ) + if( uxBlockTime > ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ) { - uxBlockTime = ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ); + uxBlockTime = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS; } /* Obtain a network buffer with the required amount of storage. */ @@ -950,7 +950,7 @@ NetworkBufferDescriptor_t *pxResult; /* The input here is a pointer to a payload buffer. Subtract the total size of a UDP/IP header plus the size of the header in the network buffer, usually 8 + 2 bytes. */ - pucBuffer -= ( sizeof( UDPPacket_t ) + ( ( size_t ) ipBUFFER_PADDING ) ); + pucBuffer -= sizeof( UDPPacket_t ) + ipBUFFER_PADDING; /* Here a pointer was placed to the network descriptor, As a pointer is dereferenced, make sure it is well aligned */ @@ -1003,7 +1003,7 @@ BaseType_t xReturn = pdFALSE; } #endif /* Attempt to create the queue used to communicate with the IP task. */ - xNetworkEventQueue = xQueueCreate( ( UBaseType_t ) ipconfigEVENT_QUEUE_LENGTH, ( UBaseType_t ) sizeof( IPStackEvent_t ) ); + xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) ); configASSERT( xNetworkEventQueue != NULL ); if( xNetworkEventQueue != NULL ) @@ -1057,9 +1057,9 @@ BaseType_t xReturn = pdFALSE; /* Create the task that processes Ethernet and stack events. */ xReturn = xTaskCreate( prvIPTask, "IP-task", - ( uint16_t )ipconfigIP_TASK_STACK_SIZE_WORDS, + ipconfigIP_TASK_STACK_SIZE_WORDS, NULL, - ( UBaseType_t )ipconfigIP_TASK_PRIORITY, + ipconfigIP_TASK_PRIORITY, &( xIPTaskHandle ) ); } else @@ -2564,6 +2564,9 @@ size_t uxDataLengthBytes = uxByteCount; void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, BaseType_t xReleaseAfterSend ) { EthernetHeader_t *pxEthernetHeader; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; #if( ipconfigZERO_COPY_TX_DRIVER != 0 ) NetworkBufferDescriptor_t *pxNewBuffer; @@ -2602,9 +2605,19 @@ EthernetHeader_t *pxEthernetHeader; /* Map the Buffer to Ethernet Header struct for easy access to fields. */ pxEthernetHeader = ipCAST_PTR_TO_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ /* Swap source and destination MAC addresses. */ - ( void ) memcpy( ( void * ) &( pxEthernetHeader->xDestinationAddress ), ( const void * ) ( &( pxEthernetHeader->xSourceAddress ) ), sizeof( pxEthernetHeader->xDestinationAddress ) ); - ( void ) memcpy( ( void * ) &( pxEthernetHeader->xSourceAddress) , ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); + pvCopySource = &pxEthernetHeader->xSourceAddress; + pvCopyDest = &pxEthernetHeader->xDestinationAddress; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( pxEthernetHeader->xDestinationAddress ) ); + + pvCopySource = ipLOCAL_MAC_ADDRESS; + pvCopyDest = &pxEthernetHeader->xSourceAddress; + ( void ) memcpy( pvCopyDest, pvCopySource, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); /* Send! */ ( void ) xNetworkInterfaceOutput( pxNetworkBuffer, xReleaseAfterSend ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c index a35a6b8ea..a62c945ee 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c @@ -839,8 +839,8 @@ TimeOut_t xTimeOut; TickType_t xTicksToWait; int32_t lReturn = 0; FreeRTOS_Socket_t const * pxSocket; -const size_t uxMaxPayloadLength = ( size_t ) ipMAX_UDP_PAYLOAD_LENGTH; -const size_t uxPayloadOffset = ( size_t ) ipUDP_PAYLOAD_OFFSET_IPv4; +const size_t uxMaxPayloadLength = ipMAX_UDP_PAYLOAD_LENGTH; +const size_t uxPayloadOffset = ipUDP_PAYLOAD_OFFSET_IPv4; pxSocket = ( FreeRTOS_Socket_t * ) xSocket; @@ -1450,9 +1450,9 @@ FreeRTOS_Socket_t *pxSocket; comments where ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined in FreeRTOSIPConfig.h (assuming an official configuration file is being used. */ - if( pxSocket->xSendBlockTime > ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ) ) + if( pxSocket->xSendBlockTime > ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ) { - pxSocket->xSendBlockTime = ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ); + pxSocket->xSendBlockTime = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS; } } else diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c index 4de4170be..4b3da1857 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c @@ -709,6 +709,9 @@ uint32_t ulFrontSpace, ulSpace, ulSourceAddress, ulWinSize; const TCPWindow_t *pxTCPWindow; NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor; NetworkBufferDescriptor_t xTempBuffer; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; /* For sending, a pseudo network buffer will be used, as explained above. */ if( pxNetworkBuffer == NULL ) @@ -912,8 +915,15 @@ NetworkBufferDescriptor_t xTempBuffer; ( const void * ) ( &( pxEthernetHeader->xSourceAddress ) ), sizeof( pxEthernetHeader->xDestinationAddress ) ); + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ /* The source MAC addresses is fixed to 'ipLOCAL_MAC_ADDRESS'. */ - ( void ) memcpy( ( void * ) ( &( pxEthernetHeader->xSourceAddress ) ), ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); + pvCopySource = ipLOCAL_MAC_ADDRESS; + pvCopyDest = &pxEthernetHeader->xSourceAddress; + ( void ) memcpy( pvCopyDest, pvCopySource, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); #if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES ) { @@ -967,8 +977,8 @@ static void prvTCPCreateWindow( FreeRTOS_Socket_t *pxSocket ) } vTCPWindowCreate( &pxSocket->u.xTCP.xTCPWindow, - ( ( size_t ) ipconfigTCP_MSS ) * pxSocket->u.xTCP.uxRxWinSize, - ( ( size_t ) ipconfigTCP_MSS ) * pxSocket->u.xTCP.uxTxWinSize, + ipconfigTCP_MSS * pxSocket->u.xTCP.uxRxWinSize, + ipconfigTCP_MSS * pxSocket->u.xTCP.uxTxWinSize, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber, pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber, ( uint32_t ) pxSocket->u.xTCP.usInitMSS ); @@ -2335,6 +2345,9 @@ ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; #if( ipconfigUSE_TCP_WIN == 1 ) if( uxOptionsLength != 0U ) @@ -2350,7 +2363,14 @@ UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength; FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 1 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber, FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 2 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber ) ); } - ( void ) memcpy( ( void * ) ( pxTCPHeader->ucOptdata ), ( const void * ) ( pxTCPWindow->ulOptionsData ), ( size_t ) uxOptionsLength ); + /* + * Use helper variables for memcpy() source & dest to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = pxTCPWindow->ulOptionsData; + pvCopyDest = pxTCPHeader->ucOptdata; + ( void ) memcpy( pvCopyDest, pvCopySource, ( size_t ) uxOptionsLength ); /* The header length divided by 4, goes into the higher nibble, effectively a shift-left 2. */ @@ -2723,7 +2743,7 @@ uint32_t ulRxBufferSpace; if( ( ulReceiveLength > 0U ) && /* Data was sent to this socket. */ ( lRxSpace >= lMinLength ) && /* There is Rx space for more data. */ ( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED ) && /* Not in a closure phase. */ - ( xSendLength == ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER ) ) && /* No Tx data or options to be sent. */ + ( xSendLength == uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER ) && /* No Tx data or options to be sent. */ ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eESTABLISHED ) && /* Connection established. */ ( pxTCPHeader->ucTCPFlags == tcpTCP_FLAG_ACK ) ) /* There are no other flags than an ACK. */ { @@ -2870,7 +2890,7 @@ UBaseType_t uxIntermediateResult = 0; /* Keep track of the highest sequence number that might be expected within this connection. */ - if( ( ipNUMERIC_CAST( int32_t, ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulHighestSequenceNumber ) ) > 0L ) + if( ( ulSequenceNumber + ulReceiveLength ) > pxTCPWindow->rx.ulHighestSequenceNumber ) { pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + ulReceiveLength; } @@ -3023,7 +3043,7 @@ static BaseType_t prvTCPSendSpecialPacketHelper( NetworkBufferDescriptor_t *pxNe { /* Map the ethernet buffer onto the TCPPacket_t struct for easy access to the fields. */ TCPPacket_t *pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); - const uint32_t ulSendLength = ( uint32_t ) + const uint32_t ulSendLength = ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */ pxTCPPacket->xTCPHeader.ucTCPFlags = ucTCPFlags; @@ -3235,7 +3255,7 @@ const IPHeader_t *pxIPHeader; /* Update the copy of the TCP header only (skipping eth and IP headers). It might be used later on, whenever data must be sent to the peer. */ - const size_t lOffset = ipNUMERIC_CAST( size_t, ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ); + const size_t lOffset = ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ); ( void ) memcpy( ( void * ) ( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ lOffset ] ) ), ( const void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ lOffset ] ) ), ipSIZE_OF_TCP_HEADER ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c index 62e6baf7c..35112bd14 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c @@ -80,6 +80,9 @@ IPHeader_t *pxIPHeader; eARPLookupResult_t eReturned; uint32_t ulIPAddress = pxNetworkBuffer->ulIPAddress; size_t uxPayloadSize; +/* memcpy() helper variables for MISRA Rule 21.15 compliance*/ +const void *pvCopySource; +void *pvCopyDest; /* Map the UDP packet onto the start of the frame. */ pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); @@ -152,9 +155,15 @@ size_t uxPayloadSize; * Offset the memcpy by the size of a MAC address to start at the packet's * Ethernet header 'source' MAC address; the preceding 'destination' should not be altered. */ + /* + * Use helper variables for memcpy() to remain + * compliant with MISRA Rule 21.15. These should be + * optimized away. + */ + pvCopySource = xDefaultPartUDPPacketHeader.ucBytes; /* The Ethernet source address is at offset 6. */ - char *pxUdpSrcAddrOffset = ( char *) ( &( pxNetworkBuffer->pucEthernetBuffer[ sizeof( MACAddress_t ) ] ) ); - ( void ) memcpy( ( void * ) pxUdpSrcAddrOffset, ( const void * ) ( xDefaultPartUDPPacketHeader.ucBytes ), sizeof( xDefaultPartUDPPacketHeader ) ); + pvCopyDest = &pxNetworkBuffer->pucEthernetBuffer[ sizeof( MACAddress_t ) ]; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xDefaultPartUDPPacketHeader ) ); #if ipconfigSUPPORT_OUTGOING_PINGS == 1 if( pxNetworkBuffer->usPort == ( uint16_t ) ipPACKET_CONTAINS_ICMP_DATA )