Skip to content

Commit 1630e69

Browse files
committed
Fix MISRA C 2012 Rule 20.4: Replace #define static with STATIC macro
Replace `#define static` with `#define STATIC static` to prevent the macro from shadowing the C `static` keyword. This also ensures static variables in `vApplicationGetIdleTaskMemory()` and `vApplicationGetPassiveIdleTaskMemory()` remain static even when portREMOVE_STATIC_QUALIFIER is defined, preventing use-after-free bugs from stack-allocated storage.
1 parent a8c9d35 commit 1630e69

2 files changed

Lines changed: 95 additions & 91 deletions

File tree

croutine.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,26 @@
3838
* than file scope.
3939
*/
4040
#ifdef portREMOVE_STATIC_QUALIFIER
41-
#define static
41+
#define STATIC
42+
#else
43+
#define STATIC static
4244
#endif
4345

4446

4547
/* Lists for ready and blocked co-routines. --------------------*/
46-
static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /**< Prioritised ready co-routines. */
47-
static List_t xDelayedCoRoutineList1; /**< Delayed co-routines. */
48-
static List_t xDelayedCoRoutineList2; /**< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
49-
static List_t * pxDelayedCoRoutineList = NULL; /**< Points to the delayed co-routine list currently being used. */
50-
static List_t * pxOverflowDelayedCoRoutineList = NULL; /**< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
51-
static List_t xPendingReadyCoRoutineList; /**< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
48+
STATIC List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /**< Prioritised ready co-routines. */
49+
STATIC List_t xDelayedCoRoutineList1; /**< Delayed co-routines. */
50+
STATIC List_t xDelayedCoRoutineList2; /**< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
51+
STATIC List_t * pxDelayedCoRoutineList = NULL; /**< Points to the delayed co-routine list currently being used. */
52+
STATIC List_t * pxOverflowDelayedCoRoutineList = NULL; /**< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
53+
STATIC List_t xPendingReadyCoRoutineList; /**< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
5254

5355
/* Other file private variables. --------------------------------*/
5456
CRCB_t * pxCurrentCoRoutine = NULL;
55-
static UBaseType_t uxTopCoRoutineReadyPriority = ( UBaseType_t ) 0U;
56-
static TickType_t xCoRoutineTickCount = ( TickType_t ) 0U;
57-
static TickType_t xLastTickCount = ( TickType_t ) 0U;
58-
static TickType_t xPassedTicks = ( TickType_t ) 0U;
57+
STATIC UBaseType_t uxTopCoRoutineReadyPriority = ( UBaseType_t ) 0U;
58+
STATIC TickType_t xCoRoutineTickCount = ( TickType_t ) 0U;
59+
STATIC TickType_t xLastTickCount = ( TickType_t ) 0U;
60+
STATIC TickType_t xPassedTicks = ( TickType_t ) 0U;
5961

6062
/* The initial state of the co-routine when it is created. */
6163
#define corINITIAL_STATE ( 0 )
@@ -80,15 +82,15 @@
8082
* Utility to ready all the lists used by the scheduler. This is called
8183
* automatically upon the creation of the first co-routine.
8284
*/
83-
static void prvInitialiseCoRoutineLists( void );
85+
STATIC void prvInitialiseCoRoutineLists( void );
8486

8587
/*
8688
* Co-routines that are readied by an interrupt cannot be placed directly into
8789
* the ready lists (there is no mutual exclusion). Instead they are placed in
8890
* in the pending ready list in order that they can later be moved to the ready
8991
* list by the co-routine scheduler.
9092
*/
91-
static void prvCheckPendingReadyList( void );
93+
STATIC void prvCheckPendingReadyList( void );
9294

9395
/*
9496
* Macro that looks at the list of co-routines that are currently delayed to
@@ -98,7 +100,7 @@
98100
* meaning once one co-routine has been found whose timer has not expired
99101
* we need not look any further down the list.
100102
*/
101-
static void prvCheckDelayedList( void );
103+
STATIC void prvCheckDelayedList( void );
102104

103105
/*-----------------------------------------------------------*/
104106

@@ -212,7 +214,7 @@
212214
}
213215
/*-----------------------------------------------------------*/
214216

215-
static void prvCheckPendingReadyList( void )
217+
STATIC void prvCheckPendingReadyList( void )
216218
{
217219
/* Are there any co-routines waiting to get moved to the ready list? These
218220
* are co-routines that have been readied by an ISR. The ISR cannot access
@@ -235,7 +237,7 @@
235237
}
236238
/*-----------------------------------------------------------*/
237239

238-
static void prvCheckDelayedList( void )
240+
STATIC void prvCheckDelayedList( void )
239241
{
240242
CRCB_t * pxCRCB;
241243

@@ -333,7 +335,7 @@
333335
}
334336
/*-----------------------------------------------------------*/
335337

336-
static void prvInitialiseCoRoutineLists( void )
338+
STATIC void prvInitialiseCoRoutineLists( void )
337339
{
338340
UBaseType_t uxPriority;
339341

0 commit comments

Comments
 (0)