Skip to content

Commit 16dcb1f

Browse files
Fix MISRA 2012 violations (#1272)
* Fix MISRA 2012 violations * Fix formatting
1 parent 90d88d7 commit 16dcb1f

File tree

7 files changed

+27
-3
lines changed

7 files changed

+27
-3
lines changed

MISRA.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ with ( Assuming rule 11.4 violation; with justification in point 2 ):
2222
grep 'MISRA Ref 11.4.2' . -rI
2323
```
2424

25+
#### Directive 4.7
26+
27+
_Ref 4.7.1_
28+
29+
- MISRA C:2012 Directive 4.7: Return value shall be checked.
30+
MISRA warns against not checking the return value of functions that
31+
does return. However, the violations reported in FreeRTOS-Plus-TCP
32+
library for this directive are for the cases where the validity of the
33+
subsequent expressions are validated by ways other than return
34+
value of the called function, for example pointer value
35+
that was passed as argument.
36+
2537
#### Directive 4.12
2638

2739
_Ref 4.12.1_

source/FreeRTOS_ARP.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@
926926
}
927927
}
928928
}
929-
else if( xIsIPv4Broadcast( ulAddressToLookup, ppxEndPoint ) )
929+
else if( xIsIPv4Broadcast( ulAddressToLookup, ppxEndPoint ) == pdTRUE )
930930
{
931931
/* This is a broadcast so it uses the broadcast MAC address. */
932932
( void ) memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );

source/FreeRTOS_DHCP.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
}
231231
else
232232
{
233+
/* do nothing, coverity happy */
233234
}
234235

235236
break;

source/FreeRTOS_DHCPv6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ void vDHCPv6Process( BaseType_t xReset,
442442
}
443443
else
444444
{
445+
/* do nothing, coverity happy */
445446
}
446447

447448
break;

source/FreeRTOS_IP_Utils.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,9 @@ void vReleaseSinglePacketFromUDPSocket( const ConstSocket_t xSocket )
18351835
int32_t lBytes;
18361836

18371837
/* Passing the address of a pointer (pucUDPPayload) because FREERTOS_ZERO_COPY is used. */
1838+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
1839+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#directive-47. */
1840+
/* coverity[misra_c_2012_directive_4_7_violation] */
18381841
lBytes = FreeRTOS_recvfrom( xSocket, &pucUDPPayload, 0U, FREERTOS_ZERO_COPY, NULL, NULL );
18391842

18401843
( void ) lBytes;

source/FreeRTOS_IPv4.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,18 @@ BaseType_t xIsIPv4Broadcast( uint32_t ulIPAddress,
253253
xIsBroadcast = pdTRUE;
254254
break;
255255
}
256+
else
257+
{
258+
/* do nothing, coverity happy */
259+
}
256260
}
257261

258262
/* If the caller wants to know the corresponding endpoint, copy the result.
259263
* Note that this may be null if ulIPAddress is 255.255.255.255 AND there are
260264
* no IPv4 endpoints.
261265
* Also, when ulIPAddress is 255.255.255.255, we will
262266
* return the first IPv4 endpoint that we run across. */
263-
if( xIsBroadcast && ( ppxEndPoint != NULL ) )
267+
if( ( xIsBroadcast == pdTRUE ) && ( ppxEndPoint != NULL ) )
264268
{
265269
*ppxEndPoint = pxEndPoint;
266270
}
@@ -347,7 +351,7 @@ enum eFrameProcessingResult prvAllowIPPacketIPv4( const struct xIP_PACKET * cons
347351
uint32_t ulDestinationIPAddress = pxIPHeader->ulDestinationIPAddress;
348352
uint32_t ulSourceIPAddress = pxIPHeader->ulSourceIPAddress;
349353
/* Get a reference to the endpoint that the packet was assigned to during pxEasyFit() */
350-
NetworkEndPoint_t * pxEndPoint = pxNetworkBuffer->pxEndPoint;
354+
const NetworkEndPoint_t * pxEndPoint = pxNetworkBuffer->pxEndPoint;
351355

352356
/* Ensure that the incoming packet is not fragmented because the stack
353357
* doesn't not support IP fragmentation. All but the last fragment coming in will have their

source/FreeRTOS_TCP_Transmission.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,9 @@
13611361
uint32_t ulCurrentSequenceNumber,
13621362
uint32_t ulOurSequenceNumber )
13631363
{
1364+
/* MISRA Ref 11.3.1 [Misaligned access] */
1365+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
1366+
/* coverity[misra_c_2012_rule_11_3_violation] */
13641367
ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * )
13651368
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) );
13661369

0 commit comments

Comments
 (0)