From 66c3f69928d56d539d659d06527d8890e66c74ba Mon Sep 17 00:00:00 2001 From: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri, 19 Dec 2025 12:12:44 -0800 Subject: [PATCH] Add asserts to check stack overflow at task creation This commit adds assert to allow developers to check for overflow of undersized task stack during task creation. --- tasks.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tasks.c b/tasks.c index 1e6ecdc9ed..104ea61cd1 100644 --- a/tasks.c +++ b/tasks.c @@ -2010,6 +2010,16 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, } #endif /* portUSING_MPU_WRAPPERS */ + #if ( portSTACK_GROWTH < 0 ) + { + configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxTopOfStack - pxNewTCB->pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) ); + } + #else /* portSTACK_GROWTH */ + { + configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxNewTCB->pxTopOfStack - pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) ); + } + #endif + /* Initialize task state and task attributes. */ #if ( configNUMBER_OF_CORES > 1 ) {