Handle null parser in WeaselJsonParser_reset and _destroy #42

Merged
andrew merged 1 commits from weaselbot/weaseljson:weaselbot/issue-41 into main 2026-06-29 18:26:49 +00:00
Member

Closes #41

Closes #41
weaselbot added 1 commit 2026-06-29 17:53:43 +00:00
Handle null parser in WeaselJsonParser_reset and _destroy
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (pull_request) Successful in 50s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (pull_request) Successful in 51s
CI / pre-commit (pull_request) Successful in 52s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (pull_request) Successful in 1m29s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (pull_request) Successful in 1m24s
34fc22a7c2
WeaselJsonParser_create can return nullptr when allocation fails or the
requested stack size is too small. Previously, passing that nullptr to
WeaselJsonParser_reset or WeaselJsonParser_destroy dereferenced it before
doing any work, causing immediate undefined behavior.

Add an early null check to both functions so they behave like free(nullptr)
(i.e., are a safe no-op). Also add a doctest case covering both a null
returned from create and a literal nullptr.

Closes #41
andrew merged commit 6508616edc into main 2026-06-29 18:26:49 +00:00
andrew deleted branch weaselbot/issue-41 2026-06-29 18:26:49 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#42