Capture strchr to a const char - #160
Merged
Merged
Conversation
Contributor
|
You'll need to fix the broken build / test. |
gcc 16 is stricter about strchr() on a const string, and these all failed -Werror=discarded-qualifiers building against it: schema.c:1244:9: error: assignment discards 'const' qualifier from pointer target type 1244 | key = strchr (path, '/'); lookup_node(), sch_node_find_name(), _sch_path_to_gnode(), sch_path_to_query() and _sch_json_to_gnode() all scan a "const char *path"/"name" for a separator and then only ever read the result - to measure a length, to compare against another position, or to step past a prefix. Declare those scan pointers const to match. lookup_node() needed a little more care because "key" was doing two jobs: first holding the strchr() result, then owning the g_strndup() copy that is written through and freed. Give the scan its own const pointer and leave "key" as the owned string. _sch_query_to_gnode() takes a "char *query" but g_strdup()s it before doing anything, so it never writes through the caller's pointer. Make the parameter const and keep the mutable copy in its own local, which also lets sch_query_to_gnode() drop the (char *) cast it was using to get around this. No functional change. Assisted-by: Claude: claude-opus-5
sparlane
force-pushed
the
const_char_strchr
branch
from
August 31, 2026 23:37
6f974df to
7a2dfb7
Compare
blairsteven
approved these changes
Aug 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
strchr returns const char *, and we only need to read the returned pointer, so don't try to remove the const.