global: constify some pointers that are not written to
The recent glibc 2.43 release had the following change listed in its
NEWS file:
For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
pointers into their input arrays now have definitions as macros that
return a pointer to a const-qualified type when the input argument is
a pointer to a const-qualified type.
When compiling with GCC 15, which defaults to -std=gnu23, this causes
many warnings like this:
merge-ort.c: In function ‘apply_directory_rename_modifications’:
merge-ort.c:2734:36: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
2734 | char *last_slash = strrchr(cur_path, '/');
| ^~~~~~~
This patch fixes the more obvious ones by making them const when we do
not write to the returned pointer.
Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Collin Funk committedFeb 5, 2026 at 17:46 UTC4ac4705afa3ab660e206c2b870bfae2ddb647ffa
index 7f6d53b473..156f2a24fa 100644--- a/config.c+++ b/config.c@@ -160,7 +160,7 @@ static int handle_path_include(const struct key_value_info *kvi, * based on the including config file. */ if (!is_absolute_path(path)) {- char *slash;+ const char *slash; if (!kvi || kvi->origin_type != CONFIG_ORIGIN_FILE) { ret = error(_("relative config includes must come from files"));
convert.c
+2-1
index c7d6a85c22..a34ec6ecdc 100644--- a/convert.c+++ b/convert.c@@ -1122,7 +1122,8 @@ static int count_ident(const char *cp, unsigned long size) static int ident_to_git(const char *src, size_t len, struct strbuf *buf, int ident) {- char *dst, *dollar;+ char *dst;+ const char *dollar; if (!ident || (src && !count_ident(src, len))) return 0;
diff.c
+2-2
index a68ddd2168..2d92665159 100644--- a/diff.c+++ b/diff.c@@ -1961,7 +1961,7 @@ static int fn_out_diff_words_write_helper(struct diff_options *o, struct strbuf sb = STRBUF_INIT; while (count) {- char *p = memchr(buf, '\n', count);+ const char *p = memchr(buf, '\n', count); if (print) strbuf_addstr(&sb, diff_line_prefix(o));@@ -3049,7 +3049,7 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir, struct dirstat_file *f = dir->files; int namelen = strlen(f->name); unsigned long changes;- char *slash;+ const char *slash; if (namelen < baselen) break;