Skip to content

Add NULL-pointer assertion for pxList in vListInsert - #1532

Open
aniruddhajoshi876 wants to merge 10 commits into
FreeRTOS:mainfrom
aniruddhajoshi876:patch-1
Open

aniruddhajoshi876 wants to merge 10 commits into
FreeRTOS:mainfrom
aniruddhajoshi876:patch-1

Conversation

@aniruddhajoshi876

@aniruddhajoshi876 aniruddhajoshi876 commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

Adds configASSERT( pxList != NULL ) to vListInsert(), before pxList is first dereferenced.

Motivation

While debugging my application, I encountered a case where custom event-handling code attempted to insert an item into a list before the list pointer had been assigned. The pointer was NULL when passed to vListInsert(), resulting in a HardFault during list traversal.

The fault occurred inside the kernel rather than at the point where the invalid argument entered the function, making the cause harder to identify. This motivated me to add configASSERT( pxList != NULL ) before the first dereference. With assertions enabled, this catches the invalid argument at the function boundary and provides a clearer starting point for debugging.

The assertion does not fix the underlying application error or detect every form of list corruption. With configASSERT() undefined there is no behavioural or size change.

The assert is placed after the local declarations and traceENTER_vListInsert(), in keeping with the C90 / MISRA style used in the kernel.

Testing

  • Syntax-checked list.c with gcc (-std=c99 -Wall -Wextra -Wdeclaration-after-statement).
  • The CMock unit tests (in the FreeRTOS repo) have not been run.

@aniruddhajoshi876 aniruddhajoshi876 changed the title Add assertion to vListInsert for non-null list Add assertion for null checks Nov 6, 2026
@aniruddhajoshi876 aniruddhajoshi876 changed the title Add assertion for null checks Add assertions for null checks Nov 6, 2026
Added detailed comments regarding stack initialization and buffer guarantees.
@aniruddhajoshi876 aniruddhajoshi876 changed the title Add assertions for null checks Add assertions for null checks and documentation Nov 6, 2026
Restore listREMOVE_ITEM line continuations, add missing semicolon, place asserts after declarations (C90), and revert unrelated tasks.c and MSVC-MingW port changes.
@aniruddhajoshi876 aniruddhajoshi876 changed the title Add assertions for null checks and documentation Add defensive NULL-pointer assertions in list and stream buffer internals Nov 14, 2026
@aniruddhajoshi876 aniruddhajoshi876 changed the title Add defensive NULL-pointer assertions in list and stream buffer internals Add NULL-pointer assertion for pxList in vListInsert Nov 14, 2026
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant