fix(cli): const-qualify local pointers in codex_hook_strip for gcc 15#588
Merged
DeusData merged 1 commit intoJun 23, 2026
Merged
Conversation
Under -D_GNU_SOURCE with optimization, glibc's string.h macros make
strstr() on a `const char *` (with a constant needle) yield a
`const char *`. gcc 15 then rejects assigning that to `char *` with
-Werror=discarded-qualifiers, breaking the build:
src/cli/cli.c:1503: error: initialization discards 'const'
qualifier from pointer target type [-Werror=discarded-qualifiers]
Minimal repro (gcc 15.2):
const char *c = "hello";
char *p = strstr(c, "ell"); // gcc -D_GNU_SOURCE -O2 -Werror=discarded-qualifiers
codex_hook_strip only reads through begin/end/cut (offset math and
byte comparisons, never writes), so making them `const char *` is the
correct fix and preserves the function's existing const contract
(`content` is already const). The malloc'd output buffer stays char *.
No behavior change; build succeeds on gcc 15.2.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Jeremy Maserang <gothuncc@gothaunty.com>
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.
Problem
Building from source with gcc 15 (Ubuntu 25.x ships 15.2) fails:
This blocks
scripts/build.shon modern toolchains. Every other source file (including all 158 vendored grammars) compiles cleanly — this is the only blocker.Cause
Makefile.cbmbuilds with-D_GNU_SOURCE -O2, which enables glibc's optimizedstring.hmacros. Under those,strstr()called on aconst char *(with a constant needle) returns aconst char *. Assigning that to achar *trips-Werror=discarded-qualifierson gcc 15.Minimal reproducer (gcc 15.2):
(Compiles clean without
-D_GNU_SOURCE -O2, which is why it only surfaces in the real build.)Fix
codex_hook_strip()only ever reads throughbegin,end, andcut(offset arithmetic and byte comparisons — never writes through them), so const-qualifying the three locals is the correct fix. It also matches the function's existing const contract:contentis already declaredconst char *. Themalloc'd output buffer (out) stayschar *.No behavior change.
Testing
scripts/build.shcompletes cleanly with the patch.scripts/lint.shlocally (no clang in my environment); the change conforms to surrounding style and builds under-Wall -Wextra -Werror.