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
14 changes: 13 additions & 1 deletion MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ _Ref 8.4.1_
a declaration in header file is not useful as the assembly code will
still need to declare it separately.

#### 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 convenience only when `configUSE_TRACE_FACILITY`
chinglee-iot marked this conversation as resolved.
Show resolved Hide resolved
is set to 1 and `configUSE_STATS_FORMATTING_FUNCTIONS` is set to greater
than 0. Do not consider it to be part of the scheduler.

### MISRA configuration

Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
Expand Down Expand Up @@ -69,4 +81,4 @@ Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
}
]
}
```
```
18 changes: 18 additions & 0 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -7226,6 +7226,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 @@ -7235,6 +7238,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 @@ -7365,6 +7371,9 @@ 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",
Expand All @@ -7375,6 +7384,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%u%%\r\n",
Expand All @@ -7389,6 +7401,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 @@ -7398,6 +7413,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