Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress MISRA C:2012 rule 21.6 for snprintf #877

Merged
merged 15 commits into from
Dec 7, 2023
Merged
13 changes: 12 additions & 1 deletion MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ _Ref 8.4.1_
a declaration in header file is not useful as the assembly code will
still need to declare it separately.


#### Rule 11.3

MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to
Expand Down Expand Up @@ -87,6 +86,18 @@ _Ref 11.5.5_
because data storage buffers are implemented as uint8_t arrays for the
ease of sizing, alignment and access.

#### Rule 21.6

_Ref 21.6.1_

- MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not
be used.
This rule warns about the use of standard library input/output functions
as they might have implementation defined or undefined behavior. The function
'snprintf' is used for debugging only ( when configUSE_TRACE_FACILITY is
set to 1 and configUSE_STATS_FORMATTING_FUNCTIONS is set to greater than 0 )
and is not part of the 'core' kernel code.


### MISRA configuration

Expand Down
20 changes: 19 additions & 1 deletion tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -7338,6 +7338,9 @@ static void prvResetNextTaskUnblockTime( void )
{
/* Write the rest of the string. */
#if ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
/* MISRA Ref 21.6.1 [snprintf for utility] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
/* coverity[misra_c_2012_rule_21_6_violation] */
iSnprintfReturnValue = snprintf( pcWriteBuffer,
uxBufferLength - uxConsumedBufferLength,
"\t%c\t%u\t%u\t%u\t0x%x\r\n",
Expand All @@ -7347,6 +7350,9 @@ static void prvResetNextTaskUnblockTime( void )
( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber,
( 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. */
#else /* ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
/* MISRA Ref 21.6.1 [snprintf for utility] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
/* coverity[misra_c_2012_rule_21_6_violation] */
iSnprintfReturnValue = snprintf( pcWriteBuffer,
uxBufferLength - uxConsumedBufferLength,
"\t%c\t%u\t%u\t%u\r\n",
Expand Down Expand Up @@ -7485,16 +7491,22 @@ static void prvResetNextTaskUnblockTime( void )
{
#ifdef portLU_PRINTF_SPECIFIER_REQUIRED
{
/* MISRA Ref 21.6.1 [snprintf for utility] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
/* coverity[misra_c_2012_rule_21_6_violation] */
iSnprintfReturnValue = snprintf( pcWriteBuffer,
uxBufferLength - uxConsumedBufferLength,
"\t%lu\t\t%lu%%\r\n",
pxTaskStatusArray[ x ].ulRunTimeCounter,
ulStatsAsPercentage );
}
#else
#else /* ifdef portLU_PRINTF_SPECIFIER_REQUIRED */
{
/* sizeof( int ) == sizeof( long ) so a smaller
* printf() library can be used. */
/* MISRA Ref 21.6.1 [snprintf for utility] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
/* coverity[misra_c_2012_rule_21_6_violation] */
iSnprintfReturnValue = snprintf( pcWriteBuffer,
uxBufferLength - uxConsumedBufferLength,
"\t%u\t\t%u%%\r\n",
Expand All @@ -7509,6 +7521,9 @@ static void prvResetNextTaskUnblockTime( void )
* consumed less than 1% of the total run time. */
#ifdef portLU_PRINTF_SPECIFIER_REQUIRED
{
/* MISRA Ref 21.6.1 [snprintf for utility] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
/* coverity[misra_c_2012_rule_21_6_violation] */
iSnprintfReturnValue = snprintf( pcWriteBuffer,
uxBufferLength - uxConsumedBufferLength,
"\t%lu\t\t<1%%\r\n",
Expand All @@ -7518,6 +7533,9 @@ static void prvResetNextTaskUnblockTime( void )
{
/* sizeof( int ) == sizeof( long ) so a smaller
* printf() library can be used. */
/* MISRA Ref 21.6.1 [snprintf for utility] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-216 */
/* coverity[misra_c_2012_rule_21_6_violation] */
iSnprintfReturnValue = snprintf( pcWriteBuffer,
uxBufferLength - uxConsumedBufferLength,
"\t%u\t\t<1%%\r\n",
Expand Down
Loading