Skip to content

Commit 1a0f0cd

Browse files
authored
Merge branch 'main' into posix_port
2 parents 92be5d4 + f94bc89 commit 1a0f0cd

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

MISRA.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,25 @@ _Ref 11.5.5_
115115
because data storage buffers are implemented as uint8_t arrays for the
116116
ease of sizing, alignment and access.
117117

118+
#### Rule 14.3
119+
120+
MISRA C-2012 Rule 14.3: Controlling expressions shall not be invariant.
121+
122+
_Ref 14.3_
123+
- The `configMAX_TASK_NAME_LEN` and `taskRESERVED_TASK_NAME_LENGTH` are
124+
evaluated to constants at compile time and may vary based on the build
125+
configuration.
126+
127+
#### Rule 18.1
128+
129+
MISRA C-2012 Rule 18.1: A pointer resulting from arithmetic on a pointer operand
130+
shall address an element of the same array as that pointer operand.
131+
132+
_Ref 18.1_
133+
- Array access remains within bounds since either the null terminator in
134+
the IDLE task name will break the loop, or the loop will break normally
135+
if the array size is smaller than the IDLE task name length.
136+
118137
#### Rule 21.6
119138

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

tasks.c

Lines changed: 34 additions & 12 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 > 9 )
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
@@ -3527,21 +3544,26 @@ static BaseType_t prvCreateIdleTasks( void )
35273544
BaseType_t xCoreID;
35283545
char cIdleName[ configMAX_TASK_NAME_LEN ] = { 0 };
35293546
TaskFunction_t pxIdleTaskFunction = NULL;
3530-
BaseType_t xIdleTaskNameIndex;
3531-
BaseType_t xIdleNameLen;
3532-
BaseType_t xCopyLen;
3533-
3534-
configASSERT( ( configIDLE_TASK_NAME != NULL ) && ( configMAX_TASK_NAME_LEN > 3 ) );
3535-
3536-
/* The length of the idle task name is limited to the minimum of the length
3537-
* of configIDLE_TASK_NAME and configMAX_TASK_NAME_LEN - 2, keeping space
3538-
* for the core ID suffix and the null-terminator. */
3539-
xIdleNameLen = strlen( configIDLE_TASK_NAME );
3540-
xCopyLen = xIdleNameLen < ( configMAX_TASK_NAME_LEN - 2 ) ? xIdleNameLen : ( configMAX_TASK_NAME_LEN - 2 );
3547+
UBaseType_t xIdleTaskNameIndex;
35413548

3542-
for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < xCopyLen; xIdleTaskNameIndex++ )
3549+
/* MISRA Ref 14.3.1 [Configuration dependent invariant] */
3550+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-143. */
3551+
/* coverity[misra_c_2012_rule_14_3_violation] */
3552+
for( xIdleTaskNameIndex = 0U; xIdleTaskNameIndex < ( configMAX_TASK_NAME_LEN - taskRESERVED_TASK_NAME_LENGTH ); xIdleTaskNameIndex++ )
35433553
{
3554+
/* MISRA Ref 18.1.1 [Configuration dependent bounds checking] */
3555+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-181. */
3556+
/* coverity[misra_c_2012_rule_18_1_violation] */
35443557
cIdleName[ xIdleTaskNameIndex ] = configIDLE_TASK_NAME[ xIdleTaskNameIndex ];
3558+
3559+
if( cIdleName[ xIdleTaskNameIndex ] == ( char ) 0x00 )
3560+
{
3561+
break;
3562+
}
3563+
else
3564+
{
3565+
mtCOVERAGE_TEST_MARKER();
3566+
}
35453567
}
35463568

35473569
/* Ensure null termination. */

0 commit comments

Comments
 (0)