Skip to content

Commit b5ab4b2

Browse files
Fix MISRA violations
1 parent 9905483 commit b5ab4b2

32 files changed

Lines changed: 282 additions & 265 deletions

MISRA.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ _Ref 10.5.1_
9797

9898
- MISRA C-2012 Rule 10.5 Converting from an unsigned to an enum type. The
9999
operation is safe to perform in that case, as we are using a generic API to
100-
send and receive data, in that case the exact data sent it is received
100+
send and receive data, in that case the exact data sent it is received.
101+
102+
#### Rule 10.8
103+
104+
_Ref 10.8.1_
105+
106+
- MISRA C-2012 Rule 10.8 Casting a composite expression from a signed to an
107+
unsigned type. The operation is safe to perform in this case as we have verified
108+
that the pointer being subtracted from is greater than or equal to the pointer
109+
being subtracted thereby making the result positive. This result can be safely
110+
casted to an unsigned type like size_t.
101111

102112
#### Rule 11.1
103113

source/FreeRTOS_DNS.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB
15731573
* @return Always pdFAIL to indicate that the packet was not consumed and must
15741574
* be released by the caller.
15751575
*/
1576-
uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer )
1576+
BaseType_t xDNSHandlePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer )
15771577
{
15781578
uint8_t * pucPayLoadBuffer;
15791579
size_t uxPayloadSize;

source/FreeRTOS_DNS_Parser.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
uint16_t x;
263263
BaseType_t xReturn = pdTRUE;
264264
uint32_t ulIPAddress = 0U;
265-
BaseType_t xDNSHookReturn = 0U;
265+
BaseType_t xDNSHookReturn = 0;
266266
NetworkBufferDescriptor_t * pxNewBuffer = NULL;
267267

268268
( void ) memset( &( xSet ), 0, sizeof( xSet ) );
@@ -388,6 +388,9 @@
388388
{
389389
/* Note that the Questions section turns into the Answers section.
390390
* uxSkipCount points to the first byte after e.g. 'name.local' */
391+
/* MISRA Ref 10.8.1 [Misaligned access] */
392+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-108 */
393+
/* coverity[misra_c_2012_rule_10_8_violation] */
391394
xSet.uxSkipCount = ( size_t ) ( xSet.pucByte - pucUDPPayloadBuffer );
392395
}
393396

source/FreeRTOS_IP.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static void prvProcessIPEventsAndTimers( void )
343343
switch( pxSocket->bits.bIsIPv6 ) /* LCOV_EXCL_BR_LINE */
344344
{
345345
#if ( ipconfigUSE_IPv4 != 0 )
346-
case pdFALSE_UNSIGNED:
346+
case ipFALSE_BOOL:
347347
xAddress.sin_family = FREERTOS_AF_INET;
348348
xAddress.sin_address.ulIP_IPv4 = FreeRTOS_htonl( pxSocket->xLocalAddress.ulIP_IPv4 );
349349
/* 'ulLocalAddress' will be set again by vSocketBind(). */
@@ -352,7 +352,7 @@ static void prvProcessIPEventsAndTimers( void )
352352
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
353353

354354
#if ( ipconfigUSE_IPv6 != 0 )
355-
case pdTRUE_UNSIGNED:
355+
case ipTRUE_BOOL:
356356
xAddress.sin_family = FREERTOS_AF_INET6;
357357
( void ) memcpy( xAddress.sin_address.xIP_IPv6.ucBytes, pxSocket->xLocalAddress.xIP_IPv6.ucBytes, sizeof( xAddress.sin_address.xIP_IPv6.ucBytes ) );
358358
/* 'ulLocalAddress' will be set again by vSocketBind(). */
@@ -568,10 +568,10 @@ static void prvIPTask_CheckPendingEvents( void )
568568
pxInterface != NULL;
569569
pxInterface = FreeRTOS_NextNetworkInterface( pxInterface ) )
570570
{
571-
if( pxInterface->bits.bCallDownEvent != pdFALSE_UNSIGNED )
571+
if( pxInterface->bits.bCallDownEvent != ipFALSE_BOOL )
572572
{
573573
prvProcessNetworkDownEvent( pxInterface );
574-
pxInterface->bits.bCallDownEvent = pdFALSE_UNSIGNED;
574+
pxInterface->bits.bCallDownEvent = ipFALSE_BOOL;
575575
}
576576
}
577577
}
@@ -656,7 +656,7 @@ void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint )
656656
#endif
657657
}
658658

659-
pxEndPoint->bits.bEndPointUp = pdTRUE_UNSIGNED;
659+
pxEndPoint->bits.bEndPointUp = ipTRUE_BOOL;
660660

661661
#if ( ipconfigUSE_NETWORK_EVENT_HOOK == 1 )
662662
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
@@ -762,21 +762,21 @@ void FreeRTOS_NetworkDown( struct xNetworkInterface * pxNetworkInterface )
762762
IPStackEvent_t xNetworkDownEvent;
763763
const TickType_t xDontBlock = ( TickType_t ) 0;
764764

765-
pxNetworkInterface->bits.bInterfaceUp = pdFALSE_UNSIGNED;
765+
pxNetworkInterface->bits.bInterfaceUp = ipFALSE_BOOL;
766766
xNetworkDownEvent.eEventType = eNetworkDownEvent;
767767
xNetworkDownEvent.pvData = pxNetworkInterface;
768768

769769
/* Simply send the network task the appropriate event. */
770770
if( xSendEventStructToIPTask( &xNetworkDownEvent, xDontBlock ) != pdPASS )
771771
{
772772
/* Could not send the message, so it is still pending. */
773-
pxNetworkInterface->bits.bCallDownEvent = pdTRUE;
773+
pxNetworkInterface->bits.bCallDownEvent = ipTRUE_BOOL;
774774
xNetworkDownEventPending = pdTRUE;
775775
}
776776
else
777777
{
778778
/* Message was sent so it is not pending. */
779-
pxNetworkInterface->bits.bCallDownEvent = pdFALSE;
779+
pxNetworkInterface->bits.bCallDownEvent = ipFALSE_BOOL;
780780
}
781781

782782
iptraceNETWORK_DOWN();
@@ -805,13 +805,13 @@ BaseType_t FreeRTOS_NetworkDownFromISR( struct xNetworkInterface * pxNetworkInte
805805
if( xQueueSendToBackFromISR( xNetworkEventQueue, &xNetworkDownEvent, &xHigherPriorityTaskWoken ) != pdPASS )
806806
{
807807
/* Could not send the message, so it is still pending. */
808-
pxNetworkInterface->bits.bCallDownEvent = pdTRUE;
808+
pxNetworkInterface->bits.bCallDownEvent = ipTRUE_BOOL;
809809
xNetworkDownEventPending = pdTRUE;
810810
}
811811
else
812812
{
813813
/* Message was sent so it is not pending. */
814-
pxNetworkInterface->bits.bCallDownEvent = pdFALSE;
814+
pxNetworkInterface->bits.bCallDownEvent = ipFALSE_BOOL;
815815
xNetworkDownEventPending = pdFALSE;
816816
}
817817

@@ -1773,7 +1773,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
17731773
break;
17741774
} /* switch( pxEthernetHeader->usFrameType ) */
17751775
}
1776-
} while( pdFALSE );
1776+
} while( ipFALSE_BOOL );
17771777

17781778
/* Perform any actions that resulted from processing the Ethernet frame. */
17791779
switch( eReturned )

source/FreeRTOS_IP_Timers.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,14 @@ static void prvIPTimerStart( IPTimer_t * pxTimer,
401401

402402
if( xTime == ( TickType_t ) 0 )
403403
{
404-
pxTimer->bExpired = pdTRUE_UNSIGNED;
404+
pxTimer->bExpired = ipTRUE_BOOL;
405405
}
406406
else
407407
{
408-
pxTimer->bExpired = pdFALSE_UNSIGNED;
408+
pxTimer->bExpired = ipFALSE_BOOL;
409409
}
410410

411-
pxTimer->bActive = pdTRUE_UNSIGNED;
411+
pxTimer->bActive = ipTRUE_BOOL;
412412
}
413413
/*-----------------------------------------------------------*/
414414

@@ -559,15 +559,15 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
559559
{
560560
/* The timer might have set the bExpired flag already, if not, check the
561561
* value of xTimeOut against ulRemainingTime. */
562-
if( pxTimer->bExpired == pdFALSE_UNSIGNED )
562+
if( pxTimer->bExpired == ipFALSE_BOOL )
563563
{
564564
if( xTaskCheckForTimeOut( &( pxTimer->xTimeOut ), &( pxTimer->ulRemainingTime ) ) != pdFALSE )
565565
{
566-
pxTimer->bExpired = pdTRUE_UNSIGNED;
566+
pxTimer->bExpired = ipTRUE_BOOL;
567567
}
568568
}
569569

570-
if( pxTimer->bExpired != pdFALSE_UNSIGNED )
570+
if( pxTimer->bExpired != ipFALSE_BOOL )
571571
{
572572
prvIPTimerStart( pxTimer, pxTimer->ulReloadTime );
573573
xReturn = pdTRUE;
@@ -591,15 +591,15 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
591591
*/
592592
void vIPSetTCPTimerExpiredState( BaseType_t xExpiredState )
593593
{
594-
xTCPTimer.bActive = pdTRUE_UNSIGNED;
594+
xTCPTimer.bActive = ipTRUE_BOOL;
595595

596596
if( xExpiredState != pdFALSE )
597597
{
598-
xTCPTimer.bExpired = pdTRUE_UNSIGNED;
598+
xTCPTimer.bExpired = ipTRUE_BOOL;
599599
}
600600
else
601601
{
602-
xTCPTimer.bExpired = pdFALSE_UNSIGNED;
602+
xTCPTimer.bExpired = ipFALSE_BOOL;
603603
}
604604
}
605605
#endif /* if ( ipconfigUSE_TCP == 1 ) */
@@ -616,11 +616,11 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
616616
{
617617
if( xEnableState != pdFALSE )
618618
{
619-
xARPTimer.bActive = pdTRUE_UNSIGNED;
619+
xARPTimer.bActive = ipTRUE_BOOL;
620620
}
621621
else
622622
{
623-
xARPTimer.bActive = pdFALSE_UNSIGNED;
623+
xARPTimer.bActive = ipFALSE_BOOL;
624624
}
625625
}
626626
/*-----------------------------------------------------------*/
@@ -634,11 +634,11 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
634634
{
635635
if( xEnableState != pdFALSE )
636636
{
637-
xARPResolutionTimer.bActive = pdTRUE_UNSIGNED;
637+
xARPResolutionTimer.bActive = ipTRUE_BOOL;
638638
}
639639
else
640640
{
641-
xARPResolutionTimer.bActive = pdFALSE_UNSIGNED;
641+
xARPResolutionTimer.bActive = ipFALSE_BOOL;
642642
}
643643
}
644644
#endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */
@@ -655,11 +655,11 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
655655
{
656656
if( xEnableState != pdFALSE )
657657
{
658-
xNDTimer.bActive = pdTRUE_UNSIGNED;
658+
xNDTimer.bActive = ipTRUE_BOOL;
659659
}
660660
else
661661
{
662-
xNDTimer.bActive = pdFALSE_UNSIGNED;
662+
xNDTimer.bActive = ipFALSE_BOOL;
663663
}
664664
}
665665
/*-----------------------------------------------------------*/
@@ -673,11 +673,11 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
673673
{
674674
if( xEnableState != pdFALSE )
675675
{
676-
xNDResolutionTimer.bActive = pdTRUE_UNSIGNED;
676+
xNDResolutionTimer.bActive = ipTRUE_BOOL;
677677
}
678678
else
679679
{
680-
xNDResolutionTimer.bActive = pdFALSE_UNSIGNED;
680+
xNDResolutionTimer.bActive = ipFALSE_BOOL;
681681
}
682682
}
683683
#endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) */
@@ -699,11 +699,11 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
699699
/* 'xDHCP_RATimer' is shared between DHCP (IPv4) and RA/SLAAC (IPv6). */
700700
if( xEnableState != 0 )
701701
{
702-
pxEndPoint->xDHCP_RATimer.bActive = pdTRUE_UNSIGNED;
702+
pxEndPoint->xDHCP_RATimer.bActive = ipTRUE_BOOL;
703703
}
704704
else
705705
{
706-
pxEndPoint->xDHCP_RATimer.bActive = pdFALSE_UNSIGNED;
706+
pxEndPoint->xDHCP_RATimer.bActive = ipFALSE_BOOL;
707707
}
708708
}
709709
#endif /* if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) || ( ipconfigUSE_DHCPv6 == 1 ) */
@@ -720,11 +720,11 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
720720
{
721721
if( xEnableState != 0 )
722722
{
723-
xDNSTimer.bActive = pdTRUE_UNSIGNED;
723+
xDNSTimer.bActive = ipTRUE_BOOL;
724724
}
725725
else
726726
{
727-
xDNSTimer.bActive = pdFALSE_UNSIGNED;
727+
xDNSTimer.bActive = ipFALSE_BOOL;
728728
}
729729
}
730730

source/FreeRTOS_IP_Utils.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,9 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
839839
pxEndPoint = FreeRTOS_NextEndPoint( pxInterface, pxEndPoint ) )
840840
{
841841
/* The bit 'bEndPointUp' stays low until vIPNetworkUpCalls() is called. */
842-
pxEndPoint->bits.bEndPointUp = pdFALSE_UNSIGNED;
842+
pxEndPoint->bits.bEndPointUp = ipFALSE_BOOL;
843843

844-
if( pxEndPoint->bits.bIPv6 == pdTRUE_UNSIGNED )
844+
if( pxEndPoint->bits.bIPv6 == ipTRUE_BOOL )
845845
{
846846
/* IPv6 end-points have a solicited-node address that needs extra housekeeping. */
847847
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
@@ -851,7 +851,7 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
851851

852852
#if ( ipconfigUSE_NETWORK_EVENT_HOOK == 1 )
853853
{
854-
if( pxEndPoint->bits.bCallDownHook != pdFALSE_UNSIGNED )
854+
if( pxEndPoint->bits.bCallDownHook != ipFALSE_BOOL )
855855
{
856856
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
857857
{
@@ -866,7 +866,7 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
866866
else
867867
{
868868
/* The next time NetworkEventHook will be called for this end-point. */
869-
pxEndPoint->bits.bCallDownHook = pdTRUE_UNSIGNED;
869+
pxEndPoint->bits.bCallDownHook = ipTRUE_BOOL;
870870
}
871871
}
872872
#endif /* ipconfigUSE_NETWORK_EVENT_HOOK */
@@ -887,7 +887,7 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
887887
if( END_POINT_USES_DHCP( pxEndPoint ) )
888888
{
889889
#if ( ( ipconfigUSE_DHCPv6 != 0 ) && ( ipconfigUSE_IPv6 != 0 ) )
890-
if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED )
890+
if( pxEndPoint->bits.bIPv6 != ipFALSE_BOOL )
891891
{
892892
vDHCPv6Stop( pxEndPoint );
893893
}
@@ -915,7 +915,7 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
915915

916916
if( pxInterface->pfInitialise( pxInterface ) == pdPASS )
917917
{
918-
pxInterface->bits.bInterfaceUp = pdTRUE_UNSIGNED;
918+
pxInterface->bits.bInterfaceUp = ipTRUE_BOOL;
919919
/* Set remaining time to 0 so it will become active immediately. */
920920

921921
/* The network is not up until DHCP has completed.
@@ -929,7 +929,7 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
929929
if( END_POINT_USES_DHCP( pxEndPoint ) )
930930
{
931931
#if ( ( ipconfigUSE_DHCPv6 != 0 ) && ( ipconfigUSE_IPv6 != 0 ) )
932-
if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED )
932+
if( pxEndPoint->bits.bIPv6 != ipFALSE_BOOL )
933933
{
934934
vDHCPv6Process( pdTRUE, pxEndPoint );
935935
}
@@ -956,13 +956,13 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
956956
switch( pxEndPoint->bits.bIPv6 ) /* LCOV_EXCL_BR_LINE */
957957
{
958958
#if ( ipconfigUSE_IPv4 != 0 )
959-
case pdFALSE_UNSIGNED:
959+
case ipFALSE_BOOL:
960960
( void ) memcpy( &( pxEndPoint->ipv4_settings ), &( pxEndPoint->ipv4_defaults ), sizeof( pxEndPoint->ipv4_settings ) );
961961
break;
962962
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
963963

964964
#if ( ipconfigUSE_IPv6 != 0 )
965-
case pdTRUE_UNSIGNED:
965+
case ipTRUE_BOOL:
966966
( void ) memcpy( &( pxEndPoint->ipv6_settings ), &( pxEndPoint->ipv6_defaults ), sizeof( pxEndPoint->ipv6_settings ) );
967967
break;
968968
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

source/FreeRTOS_IPv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ BaseType_t xIsIPv4Broadcast( uint32_t ulIPAddress,
236236
{
237237
#if ( ipconfigUSE_IPv6 == ipconfigENABLE )
238238
/* Skip over any IPv6 endpoints. */
239-
if( pxEndPoint->bits.bIPv6 == pdTRUE )
239+
if( pxEndPoint->bits.bIPv6 == ipTRUE_BOOL )
240240
{
241241
continue;
242242
}

source/FreeRTOS_IPv6_Utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void vManageSolicitedNodeAddress( const struct xNetworkEndPoint * pxEndPoint,
348348
pxEndPoint->pxNetworkInterface->pfRemoveAllowedMAC( pxEndPoint->pxNetworkInterface, xMACAddress.ucBytes );
349349
}
350350
}
351-
} while( pdFALSE );
351+
} while( ipFALSE_BOOL );
352352
}
353353
/*-----------------------------------------------------------*/
354354

0 commit comments

Comments
 (0)