66 *
77 * SPDX-License-Identifier: MIT
88 *
9- * SPDX-FileContributor: 2023-2024 Espressif Systems (Shanghai) CO LTD
9+ * SPDX-FileContributor: 2023-2025 Espressif Systems (Shanghai) CO LTD
1010 *
1111 * Permission is hereby granted, free of charge, to any person obtaining a copy of
1212 * this software and associated documentation files (the "Software"), to deal in
126126 #define configIDLE_TASK_NAME "IDLE"
127127#endif
128128
129+ /* Reserve space for Core ID and null termination. */
130+ #if ( configNUMBER_OF_CORES > 9 )
131+ /* More than 9 cores require 2 characters for core ID and 1 for null termination. */
132+ #if ( configMAX_TASK_NAME_LEN < 3U )
133+ #error Minimum required task name length is 3. Please increase configMAX_TASK_NAME_LEN.
134+ #endif
135+ #define taskRESERVED_TASK_NAME_LENGTH 3U
136+
137+ #elif ( configNUMBER_OF_CORES > 1 )
138+ /* Multi-core systems with up to 9 cores require 1 character for core ID and 1 for null termination. */
139+ #if ( configMAX_TASK_NAME_LEN < 2U )
140+ #error Minimum required task name length is 2. Please increase configMAX_TASK_NAME_LEN.
141+ #endif
142+ #define taskRESERVED_TASK_NAME_LENGTH 2U
143+
144+ #else /* if ( configNUMBER_OF_CORES > 9 ) */
145+ /* Reserve space for null termination. */
146+ #if ( configMAX_TASK_NAME_LEN < 1U )
147+ #error Minimum required task name length is 1. Please increase configMAX_TASK_NAME_LEN.
148+ #endif
149+ #define taskRESERVED_TASK_NAME_LENGTH 1U
150+ #endif /* if ( ( configNUMBER_OF_CORES > 1 ) */
151+
129152/*-----------------------------------------------------------*/
130153
131154/* Macros to check if an unblocked task causes a yield on the current core.
@@ -2254,21 +2277,7 @@ static BaseType_t prvCreateIdleTasks( void )
22542277 BaseType_t xCoreID ;
22552278
22562279 #if ( configNUMBER_OF_CORES > 1 )
2257-
2258- /* The code for limiting the idle task name copy length has been backported from the upstream
2259- * FreeRTOS-Kernel source. The reference for the same is on the mainline
2260- * at the commit id# f31787d35d5614620fc6fefa6c12df2583612fcf. */
22612280 char cIdleName [ configMAX_TASK_NAME_LEN ] = { 0 };
2262- BaseType_t xIdleNameLen ;
2263- BaseType_t xCopyLen ;
2264-
2265- configASSERT ( ( configIDLE_TASK_NAME != NULL ) && ( configMAX_TASK_NAME_LEN > 3 ) );
2266-
2267- /* The length of the idle task name is limited to the minimum of the length
2268- * of configIDLE_TASK_NAME and configMAX_TASK_NAME_LEN - 2, keeping space
2269- * for the core ID suffix and the null-terminator. */
2270- xIdleNameLen = strlen ( configIDLE_TASK_NAME );
2271- xCopyLen = xIdleNameLen < ( configMAX_TASK_NAME_LEN - 2 ) ? xIdleNameLen : ( configMAX_TASK_NAME_LEN - 2 );
22722281 #endif /* #if ( configNUMBER_OF_CORES > 1 ) */
22732282
22742283 /* Add each idle task at the lowest priority. */
@@ -2289,9 +2298,24 @@ static BaseType_t prvCreateIdleTasks( void )
22892298 mtCOVERAGE_TEST_MARKER ();
22902299 }
22912300
2292- for ( xIdleTaskNameIndex = ( BaseType_t ) 0 ; xIdleTaskNameIndex < xCopyLen ; xIdleTaskNameIndex ++ )
2301+ /* MISRA Ref 14.3.1 [Configuration dependent invariant] */
2302+ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-143. */
2303+ /* coverity[misra_c_2012_rule_14_3_violation] */
2304+ for ( xIdleTaskNameIndex = 0U ; xIdleTaskNameIndex < ( configMAX_TASK_NAME_LEN - taskRESERVED_TASK_NAME_LENGTH ); xIdleTaskNameIndex ++ )
22932305 {
2306+ /* MISRA Ref 18.1.1 [Configuration dependent bounds checking] */
2307+ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-181. */
2308+ /* coverity[misra_c_2012_rule_18_1_violation] */
22942309 cIdleName [ xIdleTaskNameIndex ] = configIDLE_TASK_NAME [ xIdleTaskNameIndex ];
2310+
2311+ if ( cIdleName [ xIdleTaskNameIndex ] == ( char ) 0x00 )
2312+ {
2313+ break ;
2314+ }
2315+ else
2316+ {
2317+ mtCOVERAGE_TEST_MARKER ();
2318+ }
22952319 }
22962320
22972321 /* Append the idle task number to the end of the name. */
0 commit comments