Skip to content

Commit 4ac10c8

Browse files
Misra fix or suppress remaining violations (#529)
* Fix Remaning misra issues * Suppress rule 8.6 * Fix/Suppress more misra violations * Style: for formatting * Style: fix formatting * Style: fix spelling * Fix Rule 11.1 * Fix undeteced suppressions * Enable 32 bits * Fix more misra leftover violations * Add justification for a missed violation * Fix comment for rule 8.13 * Fix comment * fix misra comments * Update MISRA.md Co-authored-by: Aniruddha Kanhere <[email protected]> * Update source/FreeRTOS_Sockets.c Co-authored-by: Aniruddha Kanhere <[email protected]> * Update source/portable/BufferManagement/BufferAllocation_2.c Co-authored-by: Aniruddha Kanhere <[email protected]> * Update MISRA.md Co-authored-by: Aniruddha Kanhere <[email protected]> * Update MISRA.md Co-authored-by: Aniruddha Kanhere <[email protected]> * Suppress Rule 8.9 * Fix build error * fix build error * Fix coverity supression bugs Co-authored-by: Aniruddha Kanhere <[email protected]>
1 parent f8c7271 commit 4ac10c8

File tree

10 files changed

+169
-66
lines changed

10 files changed

+169
-66
lines changed

MISRA.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ _Ref 8.9.1_
3131
order of execution, some variables have file scope definitions rather
3232
than function scope.
3333

34+
#### Rule 8.13
35+
_Ref 8.13.1_
36+
37+
- MISRA C-2012 Rule 8.13 Parameter passed is never used, should be declared as
38+
const. The argument passed to the `prvIPTask` function is left unused which is
39+
considered as the variable not being used and thus warranting the use of `const`.
40+
However, the FreeRTOS-kernel function `xTaskCreate` expects a function signature
41+
of type `void vSomeFunction( void * pvArgs )`. To satisfy that requirement, the
42+
function signature of `prvIPTask` does not have a `const` qualifier in the
43+
parameter signature.
44+
45+
#### Rule 10.5
46+
_Ref 10.5.1_
47+
48+
- MISRA C-2012 Rule 10.5 Converting from an unsigned to an enum type. The
49+
operation is safe to perform in that case, as we are using a generic API
50+
to send and receive data, in that case the exact data sent it is received
51+
52+
#### Rule 11.1
53+
_Ref 11.1.1_
54+
55+
- MISRA C-2012 Rule 11.1 Converting from a void pointer to a function pointer.
56+
The `FreeRTOS_setsockopt` API allows users to configure sockets by setting
57+
various options. In order to do so, the function must accept one parameter
58+
which, based on the option value, can be casted to the corresponding socket
59+
field. To that end, that parameter is of `void *` type to accommodate all values.
60+
The caller of the API is responsible for providing correct function pointer to the
61+
API. Thus, this violation can be safely suppressed.
62+
3463
#### Rule 11.3
3564
_Ref 11.3.1_
3665

@@ -107,16 +136,6 @@ _Ref 14.3.1_
107136
- MISRA C-2012 Rule 14.3 False positive as the value might be changed
108137
depending on the conditionally compiled code
109138

110-
#### Rule 21.6
111-
_Ref 21.6.1_
112-
113-
- MISRA C-2012 Rule 21.6 warns about the use of standard library input/output
114-
functions as they might have implementation defined or undefined
115-
behaviour. The function `snprintf` is used to insert information in a
116-
logging string. This is only used in a utility function which aids in
117-
debugging and is not part of the 'core' code governing the
118-
functionality of the TCP/IP stack.
119-
120139
#### Rule 17.2
121140
_Ref 17.2.1_
122141

@@ -128,10 +147,32 @@ _Ref 17.2.1_
128147
have a secondary child socket thereby limiting the number of recursive
129148
calls to one.
130149

150+
#### Rule 20.5
151+
_Ref 20.5.1_
152+
153+
- MISRA C-2012 Rule 20.5 warns against the use of #undef.
154+
FreeRTOS-Plus-TCP allows its users to set some configuration macros
155+
to modify the behavior/performance of the library according to their
156+
needs. However, the macros values must be within certain bounds.
157+
To achieve that, if the macro values lie outside of the bounds, they
158+
are undefined using `#undef` before being redefined to a proper
159+
value.
160+
131161
#### Rule 20.10
132162
_Ref 20.10.1_
133163

134164
- MISRA C-2012 Rule 20.10 warns against the use of ## concatination operator.
135165
However, in this case, it must be used to support compile time
136166
assertions in case the preprocessor does not suppport sizeof. This
137167
operation (assert) has no runtime execution.
168+
169+
#### Rule 21.6
170+
_Ref 21.6.1_
171+
172+
- MISRA C-2012 Rule 21.6 warns about the use of standard library input/output
173+
functions as they might have implementation defined or undefined
174+
behaviour. The function `snprintf` is used to insert information in a
175+
logging string. This is only used in a utility function which aids in
176+
debugging and is not part of the 'core' code governing the
177+
functionality of the TCP/IP stack.
178+

source/FreeRTOS_IP.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void prvProcessIPEventsAndTimers( void );
122122
* from the network hardware drivers and tasks that are using sockets. It also
123123
* maintains a set of protocol timers.
124124
*/
125-
static void prvIPTask( const void * pvParameters );
125+
static void prvIPTask( void * pvParameters );
126126

127127
/*
128128
* Called when new data is available from the network interface.
@@ -229,7 +229,11 @@ static BaseType_t xIPTaskInitialised = pdFALSE;
229229
*
230230
* @param[in] pvParameters: Not used.
231231
*/
232-
static void prvIPTask( const void * pvParameters )
232+
233+
/* MISRA Ref 8.13.1 [Not decorating a pointer to const parameter with const] */
234+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-813 */
235+
/* coverity[misra_c_2012_rule_8_13_violation] */
236+
static void prvIPTask( void * pvParameters )
233237
{
234238
/* Just to prevent compiler warnings about unused parameters. */
235239
( void ) pvParameters;
@@ -390,9 +394,11 @@ static void prvProcessIPEventsAndTimers( void )
390394
eDHCPState_t eState;
391395

392396
/* MISRA Ref 11.6.1 [DHCP events and conversion to void] */
393-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-116 */
397+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-116 */
394398
/* coverity[misra_c_2012_rule_11_6_violation] */
395399
uxState = ( uintptr_t ) xReceivedEvent.pvData;
400+
/* MISRA Ref 10.5.1 [DHCP events Enum] */
401+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-105 */
396402
/* coverity[misra_c_2012_rule_10_5_violation] */
397403
eState = ( eDHCPState_t ) uxState;
398404

@@ -708,6 +714,7 @@ void * FreeRTOS_GetUDPPayloadBuffer( size_t uxRequestedSizeBytes,
708714
* @return pdPASS if the task was successfully created and added to a ready
709715
* list, otherwise an error code defined in the file projdefs.h
710716
*/
717+
/* coverity[single_use] */
711718
BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
712719
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ],
713720
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
@@ -1171,7 +1178,7 @@ eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucE
11711178
/* Map the buffer onto Ethernet Header struct for easy access to fields. */
11721179

11731180
/* MISRA Ref 11.3.1 [Misaligned access] */
1174-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
1181+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
11751182
/* coverity[misra_c_2012_rule_11_3_violation] */
11761183
pxEthernetHeader = ( ( const EthernetHeader_t * ) pucEthernetBuffer );
11771184

@@ -1245,7 +1252,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
12451252
/* Map the buffer onto the Ethernet Header struct for easy access to the fields. */
12461253

12471254
/* MISRA Ref 11.3.1 [Misaligned access] */
1248-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
1255+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
12491256
/* coverity[misra_c_2012_rule_11_3_violation] */
12501257
pxEthernetHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer );
12511258

@@ -1263,7 +1270,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
12631270
if( pxNetworkBuffer->xDataLength >= sizeof( ARPPacket_t ) )
12641271
{
12651272
/* MISRA Ref 11.3.1 [Misaligned access] */
1266-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
1273+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
12671274
/* coverity[misra_c_2012_rule_11_3_violation] */
12681275
eReturned = eARPProcessPacket( ( ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ) );
12691276
}
@@ -1280,7 +1287,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
12801287
if( pxNetworkBuffer->xDataLength >= sizeof( IPPacket_t ) )
12811288
{
12821289
/* MISRA Ref 11.3.1 [Misaligned access] */
1283-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
1290+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
12841291
/* coverity[misra_c_2012_rule_11_3_violation] */
12851292
eReturned = prvProcessIPPacket( ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer );
12861293
}
@@ -1542,7 +1549,7 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP
15421549
/* pxProtPack will point to the offset were the protocols begin. */
15431550

15441551
/* MISRA Ref 11.3.1 [Misaligned access] */
1545-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
1552+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
15461553
/* coverity[misra_c_2012_rule_11_3_violation] */
15471554
pxProtPack = ( ( ProtocolPacket_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );
15481555

@@ -1610,6 +1617,10 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,
16101617
/* Check if the IP headers are acceptable and if it has our destination. */
16111618
eReturn = prvAllowIPPacket( pxIPPacket, pxNetworkBuffer, uxHeaderLength );
16121619

1620+
/* MISRA Ref 14.3.1 [Configuration dependent invariant] */
1621+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-143 */
1622+
/* coverity[misra_c_2012_rule_14_3_violation] */
1623+
/* coverity[cond_const] */
16131624
if( eReturn == eProcessBuffer )
16141625
{
16151626
/* Are there IP-options. */
@@ -1647,8 +1658,9 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,
16471658
}
16481659

16491660
/* MISRA Ref 14.3.1 [Configuration dependent invariant] */
1650-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-143 */
1661+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-143 */
16511662
/* coverity[misra_c_2012_rule_14_3_violation] */
1663+
/* coverity[const] */
16521664
if( eReturn != eReleaseBuffer )
16531665
{
16541666
/* Add the IP and MAC addresses to the ARP table if they are not
@@ -1838,7 +1850,7 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,
18381850
* fields of the IP packet. */
18391851

18401852
/* MISRA Ref 11.3.1 [Misaligned access] */
1841-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
1853+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
18421854
/* coverity[misra_c_2012_rule_11_3_violation] */
18431855
pxIPPacket = ( ( const IPPacket_t * ) pucEthernetBuffer );
18441856

@@ -1991,7 +2003,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
19912003
/* Map the Buffer to Ethernet Header struct for easy access to fields. */
19922004

19932005
/* MISRA Ref 11.3.1 [Misaligned access] */
1994-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
2006+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
19952007
/* coverity[misra_c_2012_rule_11_3_violation] */
19962008
pxEthernetHeader = ( ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer );
19972009

source/FreeRTOS_IP_Utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
/* MISRA Ref 8.9.1 [File scoped variables] */
7979
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-89 */
8080
/* coverity[misra_c_2012_rule_8_9_violation] */
81+
/* coverity[single_use] */
8182
static BaseType_t xCallEventHook = pdFALSE;
8283
#endif
8384

@@ -974,10 +975,10 @@ uint16_t usGenerateChecksum( uint16_t usSum,
974975
/* coverity[value_overwrite] */
975976
xSum.u32 = ( uint32_t ) xSum.u16[ 0 ] + xSum.u16[ 1 ];
976977

977-
/* coverity[value_overwrite] */
978978
/* MISRA Ref 2.2.1 [Unions and dead code] */
979979
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-22 */
980980
/* coverity[misra_c_2012_rule_2_2_violation] */
981+
/* coverity[value_overwrite] */
981982
xSum.u32 = ( uint32_t ) xSum.u16[ 0 ] + xSum.u16[ 1 ];
982983

983984
if( ( uxAlignBits & 1U ) != 0U )

0 commit comments

Comments
 (0)