Skip to content

Commit d95b05e

Browse files
authored
Suppress MISRA C:2012 rule 21.6 for snprintf (#877)
Suppress MISRA C:2012 rule 21.6 for snprintf
1 parent 877484c commit d95b05e

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

MISRA.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ _Ref 11.5.5_
107107
because data storage buffers are implemented as uint8_t arrays for the
108108
ease of sizing, alignment and access.
109109

110+
#### Rule 21.6
111+
112+
MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not
113+
be used.
114+
115+
_Ref 21.6.1_
116+
- The Standard Library function snprintf is used in vTaskListTasks and
117+
vTaskGetRunTimeStatistics APIs, both of which are utility functions only and
118+
are not considered part of core kernel implementation.
110119

111120
### MISRA configuration
112121

tasks.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7348,22 +7348,28 @@ static void prvResetNextTaskUnblockTime( void )
73487348
{
73497349
/* Write the rest of the string. */
73507350
#if ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
7351+
/* MISRA Ref 21.6.1 [snprintf for utility] */
7352+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
7353+
/* coverity[misra_c_2012_rule_21_6_violation] */
73517354
iSnprintfReturnValue = snprintf( pcWriteBuffer,
73527355
uxBufferLength - uxConsumedBufferLength,
73537356
"\t%c\t%u\t%u\t%u\t0x%x\r\n",
73547357
cStatus,
73557358
( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority,
73567359
( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark,
73577360
( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber,
7358-
( unsigned int ) pxTaskStatusArray[ x ].uxCoreAffinityMask ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */
7361+
( unsigned int ) pxTaskStatusArray[ x ].uxCoreAffinityMask );
73597362
#else /* ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
7363+
/* MISRA Ref 21.6.1 [snprintf for utility] */
7364+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
7365+
/* coverity[misra_c_2012_rule_21_6_violation] */
73607366
iSnprintfReturnValue = snprintf( pcWriteBuffer,
73617367
uxBufferLength - uxConsumedBufferLength,
73627368
"\t%c\t%u\t%u\t%u\r\n",
73637369
cStatus,
73647370
( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority,
73657371
( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark,
7366-
( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */
7372+
( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );
73677373
#endif /* ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
73687374
uxCharsWrittenBySnprintf = prvSnprintfReturnValueToCharsWritten( iSnprintfReturnValue, uxBufferLength - uxConsumedBufferLength );
73697375

@@ -7496,21 +7502,27 @@ static void prvResetNextTaskUnblockTime( void )
74967502
{
74977503
#ifdef portLU_PRINTF_SPECIFIER_REQUIRED
74987504
{
7505+
/* MISRA Ref 21.6.1 [snprintf for utility] */
7506+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
7507+
/* coverity[misra_c_2012_rule_21_6_violation] */
74997508
iSnprintfReturnValue = snprintf( pcWriteBuffer,
75007509
uxBufferLength - uxConsumedBufferLength,
75017510
"\t%lu\t\t%lu%%\r\n",
75027511
pxTaskStatusArray[ x ].ulRunTimeCounter,
75037512
ulStatsAsPercentage );
75047513
}
7505-
#else
7514+
#else /* ifdef portLU_PRINTF_SPECIFIER_REQUIRED */
75067515
{
75077516
/* sizeof( int ) == sizeof( long ) so a smaller
75087517
* printf() library can be used. */
7518+
/* MISRA Ref 21.6.1 [snprintf for utility] */
7519+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
7520+
/* coverity[misra_c_2012_rule_21_6_violation] */
75097521
iSnprintfReturnValue = snprintf( pcWriteBuffer,
75107522
uxBufferLength - uxConsumedBufferLength,
75117523
"\t%u\t\t%u%%\r\n",
75127524
( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter,
7513-
( unsigned int ) ulStatsAsPercentage ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */
7525+
( unsigned int ) ulStatsAsPercentage );
75147526
}
75157527
#endif /* ifdef portLU_PRINTF_SPECIFIER_REQUIRED */
75167528
}
@@ -7520,6 +7532,9 @@ static void prvResetNextTaskUnblockTime( void )
75207532
* consumed less than 1% of the total run time. */
75217533
#ifdef portLU_PRINTF_SPECIFIER_REQUIRED
75227534
{
7535+
/* MISRA Ref 21.6.1 [snprintf for utility] */
7536+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
7537+
/* coverity[misra_c_2012_rule_21_6_violation] */
75237538
iSnprintfReturnValue = snprintf( pcWriteBuffer,
75247539
uxBufferLength - uxConsumedBufferLength,
75257540
"\t%lu\t\t<1%%\r\n",
@@ -7529,10 +7544,13 @@ static void prvResetNextTaskUnblockTime( void )
75297544
{
75307545
/* sizeof( int ) == sizeof( long ) so a smaller
75317546
* printf() library can be used. */
7547+
/* MISRA Ref 21.6.1 [snprintf for utility] */
7548+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
7549+
/* coverity[misra_c_2012_rule_21_6_violation] */
75327550
iSnprintfReturnValue = snprintf( pcWriteBuffer,
75337551
uxBufferLength - uxConsumedBufferLength,
75347552
"\t%u\t\t<1%%\r\n",
7535-
( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */
7553+
( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );
75367554
}
75377555
#endif /* ifdef portLU_PRINTF_SPECIFIER_REQUIRED */
75387556
}

0 commit comments

Comments
 (0)