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
9 changes: 9 additions & 0 deletions MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ _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

MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not
be used.

_Ref 21.6.1_
- The Standard Library function snprintf is used in vTaskListTasks and
vTaskGetRunTimeStatistics APIs, both of which are utility functions only and
are not considered part of core kernel implementation.

### MISRA configuration

Expand Down
28 changes: 23 additions & 5 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -7348,22 +7348,28 @@
{
/* 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",
cStatus,
( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority,
( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark,
( 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. */
( unsigned int ) pxTaskStatusArray[ x ].uxCoreAffinityMask );
#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",
cStatus,
( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority,
( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark,
( 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. */
( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );

Check warning on line 7372 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L7372

Added line #L7372 was not covered by tests
#endif /* ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
uxCharsWrittenBySnprintf = prvSnprintfReturnValueToCharsWritten( iSnprintfReturnValue, uxBufferLength - uxConsumedBufferLength );

Expand Down Expand Up @@ -7496,21 +7502,27 @@
{
#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",
( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter,
( 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. */
( unsigned int ) ulStatsAsPercentage );
}
#endif /* ifdef portLU_PRINTF_SPECIFIER_REQUIRED */
}
Expand All @@ -7520,6 +7532,9 @@
* 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 @@ -7529,10 +7544,13 @@
{
/* 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",
( 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. */
( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );
}
#endif /* ifdef portLU_PRINTF_SPECIFIER_REQUIRED */
}
Expand Down
Loading