Skip to content

Commit 7d76dce

Browse files
Add assert check for NULL TCB handle (#1177)
Co-authored-by: ActoryOu <[email protected]>
1 parent a081ba8 commit 7d76dce

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

tasks.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
22032203
/* If null is passed in here then it is the calling task that is
22042204
* being deleted. */
22052205
pxTCB = prvGetTCBFromHandle( xTaskToDelete );
2206+
configASSERT( pxTCB != NULL );
22062207

22072208
/* Remove task from the ready/delayed list. */
22082209
if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )
@@ -2495,7 +2496,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
24952496

24962497
traceENTER_eTaskGetState( xTask );
24972498

2498-
configASSERT( pxTCB );
2499+
configASSERT( pxTCB != NULL );
24992500

25002501
#if ( configNUMBER_OF_CORES == 1 )
25012502
if( pxTCB == pxCurrentTCB )
@@ -2628,6 +2629,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
26282629
/* If null is passed in here then it is the priority of the task
26292630
* that called uxTaskPriorityGet() that is being queried. */
26302631
pxTCB = prvGetTCBFromHandle( xTask );
2632+
configASSERT( pxTCB != NULL );
2633+
26312634
uxReturn = pxTCB->uxPriority;
26322635
}
26332636
portBASE_TYPE_EXIT_CRITICAL();
@@ -2676,6 +2679,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
26762679
/* If null is passed in here then it is the priority of the calling
26772680
* task that is being queried. */
26782681
pxTCB = prvGetTCBFromHandle( xTask );
2682+
configASSERT( pxTCB != NULL );
2683+
26792684
uxReturn = pxTCB->uxPriority;
26802685
}
26812686
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
@@ -2702,6 +2707,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
27022707
/* If null is passed in here then it is the base priority of the task
27032708
* that called uxTaskBasePriorityGet() that is being queried. */
27042709
pxTCB = prvGetTCBFromHandle( xTask );
2710+
configASSERT( pxTCB != NULL );
2711+
27052712
uxReturn = pxTCB->uxBasePriority;
27062713
}
27072714
portBASE_TYPE_EXIT_CRITICAL();
@@ -2750,6 +2757,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
27502757
/* If null is passed in here then it is the base priority of the calling
27512758
* task that is being queried. */
27522759
pxTCB = prvGetTCBFromHandle( xTask );
2760+
configASSERT( pxTCB != NULL );
2761+
27532762
uxReturn = pxTCB->uxBasePriority;
27542763
}
27552764
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
@@ -2794,6 +2803,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
27942803
/* If null is passed in here then it is the priority of the calling
27952804
* task that is being changed. */
27962805
pxTCB = prvGetTCBFromHandle( xTask );
2806+
configASSERT( pxTCB != NULL );
27972807

27982808
traceTASK_PRIORITY_SET( pxTCB, uxNewPriority );
27992809

@@ -2988,6 +2998,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
29882998
taskENTER_CRITICAL();
29892999
{
29903000
pxTCB = prvGetTCBFromHandle( xTask );
3001+
configASSERT( pxTCB != NULL );
29913002

29923003
pxTCB->uxCoreAffinityMask = uxCoreAffinityMask;
29933004

@@ -3043,6 +3054,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
30433054
portBASE_TYPE_ENTER_CRITICAL();
30443055
{
30453056
pxTCB = prvGetTCBFromHandle( xTask );
3057+
configASSERT( pxTCB != NULL );
3058+
30463059
uxCoreAffinityMask = pxTCB->uxCoreAffinityMask;
30473060
}
30483061
portBASE_TYPE_EXIT_CRITICAL();
@@ -3066,6 +3079,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
30663079
taskENTER_CRITICAL();
30673080
{
30683081
pxTCB = prvGetTCBFromHandle( xTask );
3082+
configASSERT( pxTCB != NULL );
30693083

30703084
pxTCB->xPreemptionDisable = pdTRUE;
30713085
}
@@ -3089,6 +3103,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
30893103
taskENTER_CRITICAL();
30903104
{
30913105
pxTCB = prvGetTCBFromHandle( xTask );
3106+
configASSERT( pxTCB != NULL );
30923107

30933108
pxTCB->xPreemptionDisable = pdFALSE;
30943109

@@ -3122,6 +3137,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
31223137
/* If null is passed in here then it is the running task that is
31233138
* being suspended. */
31243139
pxTCB = prvGetTCBFromHandle( xTaskToSuspend );
3140+
configASSERT( pxTCB != NULL );
31253141

31263142
traceTASK_SUSPEND( pxTCB );
31273143

@@ -4194,7 +4210,7 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery )
41944210
/* If null is passed in here then the name of the calling task is being
41954211
* queried. */
41964212
pxTCB = prvGetTCBFromHandle( xTaskToQuery );
4197-
configASSERT( pxTCB );
4213+
configASSERT( pxTCB != NULL );
41984214

41994215
traceRETURN_pcTaskGetName( &( pxTCB->pcTaskName[ 0 ] ) );
42004216

@@ -4357,6 +4373,7 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery )
43574373
configASSERT( ppxTaskBuffer != NULL );
43584374

43594375
pxTCB = prvGetTCBFromHandle( xTask );
4376+
configASSERT( pxTCB != NULL );
43604377

43614378
#if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 )
43624379
{
@@ -4596,7 +4613,7 @@ BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp )
45964613

45974614
traceENTER_xTaskAbortDelay( xTask );
45984615

4599-
configASSERT( pxTCB );
4616+
configASSERT( pxTCB != NULL );
46004617

46014618
vTaskSuspendAll();
46024619
{
@@ -4978,6 +4995,7 @@ BaseType_t xTaskIncrementTick( void )
49784995

49794996
/* If xTask is NULL then set the calling task's hook. */
49804997
pxTCB = prvGetTCBFromHandle( xTask );
4998+
configASSERT( pxTCB != NULL );
49814999

49825000
/* Save the hook function in the TCB. A critical section is required as
49835001
* the value can be accessed from an interrupt. */
@@ -5007,6 +5025,7 @@ BaseType_t xTaskIncrementTick( void )
50075025

50085026
/* If xTask is NULL then set the calling task's hook. */
50095027
pxTCB = prvGetTCBFromHandle( xTask );
5028+
configASSERT( pxTCB != NULL );
50105029

50115030
/* Save the hook function in the TCB. A critical section is required as
50125031
* the value can be accessed from an interrupt. */
@@ -5984,6 +6003,8 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
59846003
( xIndex < ( BaseType_t ) configNUM_THREAD_LOCAL_STORAGE_POINTERS ) )
59856004
{
59866005
pxTCB = prvGetTCBFromHandle( xTaskToQuery );
6006+
configASSERT( pxTCB != NULL );
6007+
59876008
pvReturn = pxTCB->pvThreadLocalStoragePointers[ xIndex ];
59886009
}
59896010
else
@@ -6011,6 +6032,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
60116032
/* If null is passed in here then we are modifying the MPU settings of
60126033
* the calling task. */
60136034
pxTCB = prvGetTCBFromHandle( xTaskToModify );
6035+
configASSERT( pxTCB != NULL );
60146036

60156037
vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), pxRegions, NULL, 0 );
60166038

@@ -6141,6 +6163,7 @@ static void prvCheckTasksWaitingTermination( void )
61416163

61426164
/* xTask is NULL then get the state of the calling task. */
61436165
pxTCB = prvGetTCBFromHandle( xTask );
6166+
configASSERT( pxTCB != NULL );
61446167

61456168
pxTaskStatus->xHandle = pxTCB;
61466169
pxTaskStatus->pcTaskName = ( const char * ) &( pxTCB->pcTaskName[ 0 ] );
@@ -6357,6 +6380,7 @@ static void prvCheckTasksWaitingTermination( void )
63576380
* type. */
63586381

63596382
pxTCB = prvGetTCBFromHandle( xTask );
6383+
configASSERT( pxTCB != NULL );
63606384

63616385
#if portSTACK_GROWTH < 0
63626386
{
@@ -6389,6 +6413,7 @@ static void prvCheckTasksWaitingTermination( void )
63896413
traceENTER_uxTaskGetStackHighWaterMark( xTask );
63906414

63916415
pxTCB = prvGetTCBFromHandle( xTask );
6416+
configASSERT( pxTCB != NULL );
63926417

63936418
#if portSTACK_GROWTH < 0
63946419
{
@@ -8288,6 +8313,7 @@ TickType_t uxTaskResetEventItemValue( void )
82888313
/* If null is passed in here then it is the calling task that is having
82898314
* its notification state cleared. */
82908315
pxTCB = prvGetTCBFromHandle( xTask );
8316+
configASSERT( pxTCB != NULL );
82918317

82928318
taskENTER_CRITICAL();
82938319
{
@@ -8327,6 +8353,7 @@ TickType_t uxTaskResetEventItemValue( void )
83278353
/* If null is passed in here then it is the calling task that is having
83288354
* its notification state cleared. */
83298355
pxTCB = prvGetTCBFromHandle( xTask );
8356+
configASSERT( pxTCB != NULL );
83308357

83318358
taskENTER_CRITICAL();
83328359
{
@@ -8354,6 +8381,7 @@ TickType_t uxTaskResetEventItemValue( void )
83548381
traceENTER_ulTaskGetRunTimeCounter( xTask );
83558382

83568383
pxTCB = prvGetTCBFromHandle( xTask );
8384+
configASSERT( pxTCB != NULL );
83578385

83588386
traceRETURN_ulTaskGetRunTimeCounter( pxTCB->ulRunTimeCounter );
83598387

@@ -8381,6 +8409,8 @@ TickType_t uxTaskResetEventItemValue( void )
83818409
if( ulTotalTime > ( configRUN_TIME_COUNTER_TYPE ) 0 )
83828410
{
83838411
pxTCB = prvGetTCBFromHandle( xTask );
8412+
configASSERT( pxTCB != NULL );
8413+
83848414
ulReturn = pxTCB->ulRunTimeCounter / ulTotalTime;
83858415
}
83868416
else
@@ -8584,6 +8614,7 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
85848614
traceENTER_xTaskGetMPUSettings( xTask );
85858615

85868616
pxTCB = prvGetTCBFromHandle( xTask );
8617+
configASSERT( pxTCB != NULL );
85878618

85888619
traceRETURN_xTaskGetMPUSettings( &( pxTCB->xMPUSettings ) );
85898620

0 commit comments

Comments
 (0)