Skip to content

Commit 2b59b8a

Browse files
committed
Fix/Suppress more misra violations
1 parent 8ab696f commit 2b59b8a

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

MISRA.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ _Ref 17.2.1_
135135
have a secondary child socket thereby limiting the number of recursive
136136
calls to one.
137137

138+
#### Rule 20.5
139+
_Ref 20.5.1_
140+
141+
- MISRA C-2012 Rule 20.10 warns against the use of #undef
142+
However, in this case, it must be used to make sure some macros are
143+
defined to a certain value
144+
138145
#### Rule 20.10
139146
_Ref 20.10.1_
140147

source/FreeRTOS_IP.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucE
11711171
/* Map the buffer onto Ethernet Header struct for easy access to fields. */
11721172

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

source/include/FreeRTOSIPConfigDefaults.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@
259259

260260
#ifndef FreeRTOS_debug_printf
261261
#define FreeRTOS_debug_printf( MSG ) do {} while( ipFALSE_BOOL )
262+
/* MISRA Ref 20.5.1 [Misaligned access] */
263+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2051 */
264+
/* coverity[misra_c_2012_rule_20_5_violation] */
262265
#undef ipconfigHAS_DEBUG_PRINTF
263266
#define ipconfigHAS_DEBUG_PRINTF 0
264267
#endif
@@ -282,6 +285,9 @@
282285

283286
#ifndef FreeRTOS_printf
284287
#define FreeRTOS_printf( MSG ) do {} while( ipFALSE_BOOL )
288+
/* MISRA Ref 20.5.1 [Misaligned access] */
289+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2051 */
290+
/* coverity[misra_c_2012_rule_20_5_violation] */
285291
#undef ipconfigHAS_PRINTF
286292
#define ipconfigHAS_PRINTF 0
287293
#endif
@@ -611,6 +617,9 @@
611617
#else
612618
/* A sanity check to avoid a possible overflow of size_t. */
613619
#if ipconfigNETWORK_MTU > ( SIZE_MAX >> 1 )
620+
/* MISRA Ref 20.5.1 [Misaligned access] */
621+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2051 */
622+
/* coverity[misra_c_2012_rule_20_5_violation] */
614623
#undef ipconfigNETWORK_MTU
615624
#define ipconfigNETWORK_MTU ( SIZE_MAX >> 1 )
616625
#endif

source/portable/BufferManagement/BufferAllocation_2.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,14 @@ uint8_t * pucGetNetworkBuffer( size_t * pxRequestedSizeBytes )
215215

216216
void vReleaseNetworkBuffer( uint8_t * pucEthernetBuffer )
217217
{
218+
uint8_t * pucEthernetBufferCopy = pucEthernetBuffer;
218219
/* There is space before the Ethernet buffer in which a pointer to the
219220
* network buffer that references this Ethernet buffer is stored. Remove the
220221
* space before freeing the buffer. */
221-
if( pucEthernetBuffer != NULL )
222+
if( pucEthernetBufferCopy != NULL )
222223
{
223-
pucEthernetBuffer -= ipBUFFER_PADDING;
224-
vPortFree( ( void * ) pucEthernetBuffer );
224+
pucEthernetBufferCopy -= ipBUFFER_PADDING;
225+
vPortFree( ( void * ) pucEthernetBufferCopy );
225226
}
226227
}
227228
/*-----------------------------------------------------------*/
@@ -232,8 +233,9 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS
232233
NetworkBufferDescriptor_t * pxReturn = NULL;
233234
size_t uxCount;
234235
size_t uxMaxAllowedBytes = ( SIZE_MAX >> 1 );
236+
size_t xRequestedSizeBytesCopy = xRequestedSizeBytes;
235237

236-
if( ( xRequestedSizeBytes <= uxMaxAllowedBytes ) && ( xNetworkBufferSemaphore != NULL ) )
238+
if( ( xRequestedSizeBytesCopy <= uxMaxAllowedBytes ) && ( xNetworkBufferSemaphore != NULL ) )
237239
{
238240
/* If there is a semaphore available, there is a network buffer available. */
239241
if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS )
@@ -257,27 +259,27 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS
257259
/* Allocate storage of exactly the requested size to the buffer. */
258260
configASSERT( pxReturn->pucEthernetBuffer == NULL );
259261

260-
if( xRequestedSizeBytes > 0U )
262+
if( xRequestedSizeBytesCopy > 0U )
261263
{
262-
if( ( xRequestedSizeBytes < ( size_t ) baMINIMAL_BUFFER_SIZE ) )
264+
if( ( xRequestedSizeBytesCopy < ( size_t ) baMINIMAL_BUFFER_SIZE ) )
263265
{
264266
/* ARP packets can replace application packets, so the storage must be
265267
* at least large enough to hold an ARP. */
266-
xRequestedSizeBytes = baMINIMAL_BUFFER_SIZE;
268+
xRequestedSizeBytesCopy = baMINIMAL_BUFFER_SIZE;
267269
}
268270

269-
/* Add 2 bytes to xRequestedSizeBytes and round up xRequestedSizeBytes
271+
/* Add 2 bytes to xRequestedSizeBytesCopy and round up xRequestedSizeBytesCopy
270272
* to the nearest multiple of N bytes, where N equals 'sizeof( size_t )'. */
271-
xRequestedSizeBytes += 2U;
273+
xRequestedSizeBytesCopy += 2U;
272274

273-
if( ( xRequestedSizeBytes & ( sizeof( size_t ) - 1U ) ) != 0U )
275+
if( ( xRequestedSizeBytesCopy & ( sizeof( size_t ) - 1U ) ) != 0U )
274276
{
275-
xRequestedSizeBytes = ( xRequestedSizeBytes | ( sizeof( size_t ) - 1U ) ) + 1U;
277+
xRequestedSizeBytesCopy = ( xRequestedSizeBytesCopy | ( sizeof( size_t ) - 1U ) ) + 1U;
276278
}
277279

278280
/* Extra space is obtained so a pointer to the network buffer can
279281
* be stored at the beginning of the buffer. */
280-
pxReturn->pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xRequestedSizeBytes + ipBUFFER_PADDING );
282+
pxReturn->pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xRequestedSizeBytesCopy + ipBUFFER_PADDING );
281283

282284
if( pxReturn->pucEthernetBuffer == NULL )
283285
{
@@ -293,12 +295,15 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS
293295
* buffer storage area, then move the buffer pointer on past the
294296
* stored pointer so the pointer value is not overwritten by the
295297
* application when the buffer is used. */
298+
/* MISRA Ref 11.3.1 [Misaligned access] */
299+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
300+
/* coverity[misra_c_2012_rule_11_3_violation] */
296301
*( ( NetworkBufferDescriptor_t ** ) ( pxReturn->pucEthernetBuffer ) ) = pxReturn;
297302
pxReturn->pucEthernetBuffer += ipBUFFER_PADDING;
298303

299304
/* Store the actual size of the allocated buffer, which may be
300305
* greater than the original requested size. */
301-
pxReturn->xDataLength = xRequestedSizeBytes;
306+
pxReturn->xDataLength = xRequestedSizeBytesCopy;
302307

303308
#if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
304309
{
@@ -393,11 +398,12 @@ NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDe
393398
{
394399
size_t xOriginalLength;
395400
uint8_t * pucBuffer;
401+
size_t xSizeBytes = xNewSizeBytes;
396402

397403
xOriginalLength = pxNetworkBuffer->xDataLength + ipBUFFER_PADDING;
398-
xNewSizeBytes = xNewSizeBytes + ipBUFFER_PADDING;
404+
xSizeBytes = xSizeBytes + ipBUFFER_PADDING;
399405

400-
pucBuffer = pucGetNetworkBuffer( &( xNewSizeBytes ) );
406+
pucBuffer = pucGetNetworkBuffer( &( xSizeBytes ) );
401407

402408
if( pucBuffer == NULL )
403409
{
@@ -406,11 +412,11 @@ NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDe
406412
}
407413
else
408414
{
409-
pxNetworkBuffer->xDataLength = xNewSizeBytes;
415+
pxNetworkBuffer->xDataLength = xSizeBytes ;
410416

411-
if( xNewSizeBytes > xOriginalLength )
417+
if( xSizeBytes > xOriginalLength )
412418
{
413-
xNewSizeBytes = xOriginalLength;
419+
xSizeBytes = xOriginalLength;
414420
}
415421

416422
( void ) memcpy( pucBuffer - ipBUFFER_PADDING, pxNetworkBuffer->pucEthernetBuffer - ipBUFFER_PADDING, xNewSizeBytes );

test/Coverity/ConfigFiles/FreeRTOSIPConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
* number generation is performed via this macro to allow applications to use their
106106
* own random number generation method. For example, it might be possible to
107107
* generate a random number by sampling noise on an analogue input. */
108-
extern uint32_t ulRand();
108+
extern uint32_t ulRand( void );
109109
#define ipconfigRAND32() ulRand()
110110

111111
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the

0 commit comments

Comments
 (0)