Skip to content

Commit 759e0bf

Browse files
committed
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 - FreeRTOS#1203
1 parent b5d1b97 commit 759e0bf

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tasks.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,23 @@
156156
#define configIDLE_TASK_NAME "IDLE"
157157
#endif
158158

159+
#if ( configNUMBER_OF_CORES > 1 )
160+
/* Reserve space for Core ID and null termination */
161+
#if ( configMAX_TASK_NAME_LEN < 2U )
162+
#error Minimum required task name length is 2. Please increase configMAX_TASK_NAME_LEN.
163+
#endif
164+
#define taskRESERVED_TASK_NAME_LENGTH 2U
165+
166+
#elif ( configNUMBER_OF_CORES > 10 )
167+
#warning Please increase taskRESERVED_TASK_NAME_LENGTH. 1 character is insufficient to store the core ID.
168+
#else
169+
/* Reserve space for null termination */
170+
#if ( configMAX_TASK_NAME_LEN < 1U )
171+
#error Minimum required task name length is 1. Please increase configMAX_TASK_NAME_LEN.
172+
#endif
173+
#define taskRESERVED_TASK_NAME_LENGTH 1U
174+
#endif /* if ( ( configNUMBER_OF_CORES > 1 ) */
175+
159176
#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )
160177

161178
/* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is
@@ -3531,17 +3548,27 @@ static BaseType_t prvCreateIdleTasks( void )
35313548
BaseType_t xIdleNameLen;
35323549
BaseType_t xCopyLen;
35333550

3534-
configASSERT( ( configIDLE_TASK_NAME != NULL ) && ( configMAX_TASK_NAME_LEN > 3 ) );
3535-
35363551
/* The length of the idle task name is limited to the minimum of the length
35373552
* of configIDLE_TASK_NAME and configMAX_TASK_NAME_LEN - 2, keeping space
35383553
* for the core ID suffix and the null-terminator. */
35393554
xIdleNameLen = strlen( configIDLE_TASK_NAME );
35403555
xCopyLen = xIdleNameLen < ( configMAX_TASK_NAME_LEN - 2 ) ? xIdleNameLen : ( configMAX_TASK_NAME_LEN - 2 );
35413556

3542-
for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < xCopyLen; xIdleTaskNameIndex++ )
3557+
for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < ( configMAX_TASK_NAME_LEN - taskRESERVED_TASK_NAME_LENGTH ); xIdleTaskNameIndex++ )
35433558
{
35443559
cIdleName[ xIdleTaskNameIndex ] = configIDLE_TASK_NAME[ xIdleTaskNameIndex ];
3560+
3561+
/* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than
3562+
* configMAX_TASK_NAME_LEN characters just in case the memory after the
3563+
* string is not accessible (extremely unlikely). */
3564+
if( cIdleName[ xIdleTaskNameIndex ] == ( char ) 0x00 )
3565+
{
3566+
break;
3567+
}
3568+
else
3569+
{
3570+
mtCOVERAGE_TEST_MARKER();
3571+
}
35453572
}
35463573

35473574
/* Ensure null termination. */

0 commit comments

Comments
 (0)