Skip to content

Commit c13a9db

Browse files
GothUnccclaude
andcommitted
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 <noreply@anthropic.com> Signed-off-by: Jeremy Maserang <gothuncc@gothaunty.com>
1 parent 684e35b commit c13a9db

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎src/cli/cli.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,11 +1500,11 @@ int cbm_remove_codex_mcp(const char *config_path) {
15001500
* plus a leading newline). Returns a newly-malloc'd string the caller frees, or
15011501
* NULL if no block was present (content is left untouched). */
15021502
static char *codex_hook_strip(const char *content) {
1503-
char *begin = strstr(content, CODEX_HOOK_BEGIN);
1503+
const char *begin = strstr(content, CODEX_HOOK_BEGIN);
15041504
if (!begin) {
15051505
return NULL;
15061506
}
1507-
char *end = strstr(begin, CODEX_HOOK_END);
1507+
const char *end = strstr(begin, CODEX_HOOK_END);
15081508
if (!end) {
15091509
return NULL;
15101510
}
@@ -1513,7 +1513,7 @@ static char *codex_hook_strip(const char *content) {
15131513
end++;
15141514
}
15151515
/* Drop one leading newline before the block, if any. */
1516-
char *cut = begin;
1516+
const char *cut = begin;
15171517
if (cut > content && *(cut - CLI_SKIP_ONE) == '\n') {
15181518
cut--;
15191519
}

0 commit comments

Comments
 (0)