mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-17 10:17:45 -04:00
FreeRTOS+TCP: MISRA rules 10.4, 10.8, & 21.15 (#280)
* Use unsigned types/constants where needed. * Address MISRA 21.15 violations in FreeRTOS_Sockets.c * Address MISRA rule violations in code (primarily Rule 2.2) * Inline had been disabled for Coverity builds, preventing Coverity from correctly identifying dead code; this change removes the disabling of inline during Coverity builds. * Added an explanation for the inline suppression of Rule 11.4 in prvSocketValid(). * Address MISRA Rule Violations (10.4 & 10.8) * MISRA: Rule 21.15 changes Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
This commit is contained in:
parent
5d0908b23f
commit
3f21957cc8
7 changed files with 187 additions and 47 deletions
|
@ -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 );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue