Skip to content

fix: replace global serd_output buffer with a local string via stream pointer#114

Open
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:fix/serd-output-global
Open

fix: replace global serd_output buffer with a local string via stream pointer#114
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:fix/serd-output-global

Conversation

@SoundMatt
Copy link
Copy Markdown

Problem

serd_output is a file-scope std::string that generateTripleOutput clears at the top and reads at the end. Concurrent or reentrant calls corrupt each other's output, and the global state makes the function non-reentrant by design.

Root cause

The write callback write_serd_output_to_string ignores the void* stream parameter and instead appends directly to the global. The Serd API provides the stream pointer precisely so that callers can supply per-call buffers without shared state.

Fix

Remove the global serd_output. Declare std::string local_output inside generateTripleOutput, pass &local_output as the stream argument to serd_writer_new, and update the callback to static_cast<std::string*>(stream)->append(...). Return Helper::trimTrailingNewlines(local_output) at the end.

… pointer

The file-scope serd_output string was shared across all calls to
generateTripleOutput, meaning concurrent or reentrant calls could
corrupt each other's output. The Serd write callback already receives
a void* stream pointer for exactly this purpose. Replace the global with
a local std::string in generateTripleOutput, pass its address as the
stream argument, and update the callback to cast and append through it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
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