From c13a9db612db007dd3d6323195a0d4e67d0c8769 Mon Sep 17 00:00:00 2001 From: Jeremy Maserang Date: Tue, 23 Jun 2026 15:31:56 -0400 Subject: [PATCH] fix(cli): const-qualify local pointers in codex_hook_strip for gcc 15 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 Signed-off-by: Jeremy Maserang --- src/cli/cli.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/cli.c b/src/cli/cli.c index feb4f5b24..f159f5914 100644 --- a/src/cli/cli.c +++ b/src/cli/cli.c @@ -1500,11 +1500,11 @@ int cbm_remove_codex_mcp(const char *config_path) { * plus a leading newline). Returns a newly-malloc'd string the caller frees, or * NULL if no block was present (content is left untouched). */ static char *codex_hook_strip(const char *content) { - char *begin = strstr(content, CODEX_HOOK_BEGIN); + const char *begin = strstr(content, CODEX_HOOK_BEGIN); if (!begin) { return NULL; } - char *end = strstr(begin, CODEX_HOOK_END); + const char *end = strstr(begin, CODEX_HOOK_END); if (!end) { return NULL; } @@ -1513,7 +1513,7 @@ static char *codex_hook_strip(const char *content) { end++; } /* Drop one leading newline before the block, if any. */ - char *cut = begin; + const char *cut = begin; if (cut > content && *(cut - CLI_SKIP_ONE) == '\n') { cut--; }