diff options
| author | Collin Funk <collin.funk1@gmail.com> | 2026-02-05 17:46:09 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-02-05 17:52:49 -0800 |
| commit | 4ac4705afa3ab660e206c2b870bfae2ddb647ffa (patch) | |
| tree | 491ad0c6da16c043e2c9691fec84e4d5eff7605e /builtin | |
| parent | 67ad42147a7acc2af6074753ebd03d904476118f (diff) | |
| download | git-4ac4705afa3ab660e206c2b870bfae2ddb647ffa.tar.xz | |
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>
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/commit.c | 2 | ||||
| -rw-r--r-- | builtin/receive-pack.c | 2 | ||||
| -rw-r--r-- | builtin/remote.c | 2 | ||||
| -rw-r--r-- | builtin/shortlog.c | 2 |
4 files changed, 4 insertions, 4 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index 8e901fe8db..0326546548 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -816,7 +816,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, logfile); hook_arg1 = "message"; } else if (use_message) { - char *buffer; + const char *buffer; buffer = strstr(use_message_buffer, "\n\n"); if (buffer) strbuf_addstr(&sb, skip_blank_lines(buffer + 2)); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 9c49174616..e8b6f960fa 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -393,7 +393,7 @@ struct command { static void proc_receive_ref_append(const char *prefix) { struct proc_receive_ref *ref_pattern; - char *p; + const char *p; int len; CALLOC_ARRAY(ref_pattern, 1); diff --git a/builtin/remote.c b/builtin/remote.c index 7ffc14ba15..ace390c671 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -332,7 +332,7 @@ static int config_read_branches(const char *key, const char *value, info->remote_name = xstrdup(value); break; case MERGE: { - char *space = strchr(value, ' '); + const char *space = strchr(value, ' '); value = abbrev_branch(value); while (space) { char *merge; diff --git a/builtin/shortlog.c b/builtin/shortlog.c index b91acf45c8..d80bf1a7d0 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -76,7 +76,7 @@ static void insert_one_record(struct shortlog *log, if (!eol) eol = oneline + strlen(oneline); if (starts_with(oneline, "[PATCH")) { - char *eob = strchr(oneline, ']'); + const char *eob = strchr(oneline, ']'); if (eob && (!eol || eob < eol)) oneline = eob + 1; } |
