Skip to content

fix: use dash separators in JSON filename and fix const-binding mutation#118

Open
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:fix/json-writer-filename-and-const
Open

fix: use dash separators in JSON filename and fix const-binding mutation#118
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:fix/json-writer-filename-and-const

Conversation

@SoundMatt
Copy link
Copy Markdown

Problem

Two bugs in json_writer.cpp: (a) storeJsonToFile calls getFormattedTimestampNow("%H:%M:%S", ...) to build the filename, embedding colon characters that are illegal in filenames on Windows and cause problems in URLs and shells. (b) handleAIReasonerInferenceResults iterates with const auto &[schema, section] and then writes section["AI.Reasoner.InferenceResults"] = ..., mutating through a const reference, which is undefined behaviour.

Root cause

(a) The %H:%M:%S strftime format produces colons that are valid in timestamps but not in filenames. (b) The structured binding was declared const but the loop body modifies the bound section, which nlohmann/json's items() returns as a reference to the underlying JSON value.

Fix

(a) Change the format string to "%H-%M-%S" so the filename uses dashes. (b) Change const auto &[schema, section] to auto &[schema, section] so the mutation is through a non-const reference.

…binding

Two issues in json_writer.cpp: (a) getFormattedTimestampNow was called
with format '%H:%M:%S', embedding colons in the filename which are
illegal on Windows and cause problems in URLs and shells — change to
'%H-%M-%S'. (b) handleAIReasonerInferenceResults iterated with
'const auto &[schema, section]' then wrote to section["..."], which
mutates through a const reference (undefined behaviour) — change the
binding to 'auto &'.

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