Skip to content

fix(jsonwriter): return NULL on allocation failures#1772

Merged
jpnurmi merged 3 commits into
masterfrom
jpnurmi/fix/json-writer
Jun 1, 2026
Merged

fix(jsonwriter): return NULL on allocation failures#1772
jpnurmi merged 3 commits into
masterfrom
jpnurmi/fix/json-writer

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented Jun 1, 2026

Came up at:

Track write failures in the jsonwriter so that into_string returns NULL instead of producing truncated output when allocations fail.

Change the ops function pointers to return int (0 on success) so that the callers can detect failures. Add a write_buf wrapper matching the existing write_char/write_str helpers and update write_json_str to use it instead of calling the ops directly.

Check the failed flag in can_write_item and into_string_sb to short-circuit writes and return NULL respectively.

jpnurmi added 3 commits June 1, 2026 07:00
Track write failures in the jsonwriter so that `into_string` returns
`NULL` instead of producing truncated output when allocations fail.

Change the ops function pointers to return `int` (0 on success) so
that the callers can detect failures. Add a `write_buf` wrapper
matching the existing `write_char`/`write_str` helpers and update
`write_json_str` to use it instead of calling the ops directly.

Check the `failed` flag in `can_write_item` and `into_string_sb`
to short-circuit writes and return `NULL` respectively.
@jpnurmi jpnurmi merged commit 9f49cbb into master Jun 1, 2026
99 of 100 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/fix/json-writer branch June 1, 2026 13:00
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.

3 participants