mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
fix: SA violation fixes and simplification for idle task length restrictions (#1227)
fix: SA violation fixes and simplification for idle task length restrictions This change: * Removes the dependency on strings.h for the prvCreateIdleTask function * Resolves several static analysis violations reported by tools like Parasoft Builds off of - https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/1203
This commit is contained in:
parent
b421abc7c3
commit
f94bc89108
19
MISRA.md
19
MISRA.md
|
@ -115,6 +115,25 @@ _Ref 11.5.5_
|
||||||
because data storage buffers are implemented as uint8_t arrays for the
|
because data storage buffers are implemented as uint8_t arrays for the
|
||||||
ease of sizing, alignment and access.
|
ease of sizing, alignment and access.
|
||||||
|
|
||||||
|
#### Rule 14.3
|
||||||
|
|
||||||
|
MISRA C-2012 Rule 14.3: Controlling expressions shall not be invariant.
|
||||||
|
|
||||||
|
_Ref 14.3_
|
||||||
|
- The `configMAX_TASK_NAME_LEN` and `taskRESERVED_TASK_NAME_LENGTH` are
|
||||||
|
evaluated to constants at compile time and may vary based on the build
|
||||||
|
configuration.
|
||||||
|
|
||||||
|
#### Rule 18.1
|
||||||
|
|
||||||
|
MISRA C-2012 Rule 18.1: A pointer resulting from arithmetic on a pointer operand
|
||||||
|
shall address an element of the same array as that pointer operand.
|
||||||
|
|
||||||
|
_Ref 18.1_
|
||||||
|
- Array access remains within bounds since either the null terminator in
|
||||||
|
the IDLE task name will break the loop, or the loop will break normally
|
||||||
|
if the array size is smaller than the IDLE task name length.
|
||||||
|
|
||||||
#### Rule 21.6
|
#### Rule 21.6
|
||||||
|
|
||||||
MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not
|
MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not
|
||||||
|
|
46
tasks.c
46
tasks.c
|
@ -156,6 +156,23 @@
|
||||||
#define configIDLE_TASK_NAME "IDLE"
|
#define configIDLE_TASK_NAME "IDLE"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ( configNUMBER_OF_CORES > 1 )
|
||||||
|
/* Reserve space for Core ID and null termination. */
|
||||||
|
#if ( configMAX_TASK_NAME_LEN < 2U )
|
||||||
|
#error Minimum required task name length is 2. Please increase configMAX_TASK_NAME_LEN.
|
||||||
|
#endif
|
||||||
|
#define taskRESERVED_TASK_NAME_LENGTH 2U
|
||||||
|
|
||||||
|
#elif ( configNUMBER_OF_CORES > 9 )
|
||||||
|
#warning Please increase taskRESERVED_TASK_NAME_LENGTH. 1 character is insufficient to store the core ID.
|
||||||
|
#else
|
||||||
|
/* Reserve space for null termination. */
|
||||||
|
#if ( configMAX_TASK_NAME_LEN < 1U )
|
||||||
|
#error Minimum required task name length is 1. Please increase configMAX_TASK_NAME_LEN.
|
||||||
|
#endif
|
||||||
|
#define taskRESERVED_TASK_NAME_LENGTH 1U
|
||||||
|
#endif /* if ( ( configNUMBER_OF_CORES > 1 ) */
|
||||||
|
|
||||||
#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )
|
#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )
|
||||||
|
|
||||||
/* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is
|
/* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is
|
||||||
|
@ -3527,21 +3544,26 @@ static BaseType_t prvCreateIdleTasks( void )
|
||||||
BaseType_t xCoreID;
|
BaseType_t xCoreID;
|
||||||
char cIdleName[ configMAX_TASK_NAME_LEN ] = { 0 };
|
char cIdleName[ configMAX_TASK_NAME_LEN ] = { 0 };
|
||||||
TaskFunction_t pxIdleTaskFunction = NULL;
|
TaskFunction_t pxIdleTaskFunction = NULL;
|
||||||
BaseType_t xIdleTaskNameIndex;
|
UBaseType_t xIdleTaskNameIndex;
|
||||||
BaseType_t xIdleNameLen;
|
|
||||||
BaseType_t xCopyLen;
|
|
||||||
|
|
||||||
configASSERT( ( configIDLE_TASK_NAME != NULL ) && ( configMAX_TASK_NAME_LEN > 3 ) );
|
/* MISRA Ref 14.3.1 [Configuration dependent invariant] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-143. */
|
||||||
/* The length of the idle task name is limited to the minimum of the length
|
/* coverity[misra_c_2012_rule_14_3_violation] */
|
||||||
* of configIDLE_TASK_NAME and configMAX_TASK_NAME_LEN - 2, keeping space
|
for( xIdleTaskNameIndex = 0U; xIdleTaskNameIndex < ( configMAX_TASK_NAME_LEN - taskRESERVED_TASK_NAME_LENGTH ); xIdleTaskNameIndex++ )
|
||||||
* for the core ID suffix and the null-terminator. */
|
|
||||||
xIdleNameLen = strlen( configIDLE_TASK_NAME );
|
|
||||||
xCopyLen = xIdleNameLen < ( configMAX_TASK_NAME_LEN - 2 ) ? xIdleNameLen : ( configMAX_TASK_NAME_LEN - 2 );
|
|
||||||
|
|
||||||
for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < xCopyLen; xIdleTaskNameIndex++ )
|
|
||||||
{
|
{
|
||||||
|
/* MISRA Ref 18.1.1 [Configuration dependent bounds checking] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-181. */
|
||||||
|
/* coverity[misra_c_2012_rule_18_1_violation] */
|
||||||
cIdleName[ xIdleTaskNameIndex ] = configIDLE_TASK_NAME[ xIdleTaskNameIndex ];
|
cIdleName[ xIdleTaskNameIndex ] = configIDLE_TASK_NAME[ xIdleTaskNameIndex ];
|
||||||
|
|
||||||
|
if( cIdleName[ xIdleTaskNameIndex ] == ( char ) 0x00 )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mtCOVERAGE_TEST_MARKER();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure null termination. */
|
/* Ensure null termination. */
|
||||||
|
|
Loading…
Reference in a new issue