]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/files-backend: drop const to fix strchr() warning
authorJeff King <peff@peff.net>
Thu, 2 Apr 2026 04:15:16 +0000 (00:15 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Apr 2026 05:08:53 +0000 (22:08 -0700)
In show_one_reflog_ent(), we're fed a writable strbuf buffer, which we
parse into the various reflog components. We write a NUL over email_end
to tie off one of the fields, and thus email_end must be non-const.

But with a C23 implementation of libc, strchr() will now complain when
assigning the result to a non-const pointer from a const one. So we can
fix this by making the source pointer non-const.

But there's a catch. We derive that source pointer by parsing the line
with parse_oid_hex_algop(), which requires a const pointer for its
out-parameter. We can work around that by teaching it to use our
CONST_OUTPARAM() trick, just like skip_prefix().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
hex.c
hex.h
refs/files-backend.c

diff --git a/hex.c b/hex.c
index 865a232167553d6376c51d51604544cc71813fb1..bc756722ca623beca587c511c75ebb3eece57121 100644 (file)
--- a/hex.c
+++ b/hex.c
@@ -54,9 +54,9 @@ int get_oid_hex(const char *hex, struct object_id *oid)
        return get_oid_hex_algop(hex, oid, the_hash_algo);
 }
 
-int parse_oid_hex_algop(const char *hex, struct object_id *oid,
-                       const char **end,
-                       const struct git_hash_algo *algop)
+int parse_oid_hex_algop_impl(const char *hex, struct object_id *oid,
+                            const char **end,
+                            const struct git_hash_algo *algop)
 {
        int ret = get_oid_hex_algop(hex, oid, algop);
        if (!ret)
diff --git a/hex.h b/hex.h
index e9ccb54065c0bc6f7fb8a57b65c698e1af27ee43..1e9a65d83a4f6ba783449debc4cbe53e259ec471 100644 (file)
--- a/hex.h
+++ b/hex.h
@@ -40,8 +40,10 @@ char *oid_to_hex(const struct object_id *oid);                                               /* same static buffer */
  * other invalid character.  end is only updated on success; otherwise, it is
  * unmodified.
  */
-int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end,
-                       const struct git_hash_algo *algo);
+#define parse_oid_hex_algop(hex, oid, end, algo) \
+       parse_oid_hex_algop_impl((hex), (oid), CONST_OUTPARAM((hex), (end)), (algo))
+int parse_oid_hex_algop_impl(const char *hex, struct object_id *oid, const char **end,
+                            const struct git_hash_algo *algo);
 
 /*
  * These functions work like get_oid_hex and parse_oid_hex, but they will parse
index 7ce0d574781ffde8b8441b1085f190a618be409f..ad543ad75132487938fcd5e6ed41060c7126da43 100644 (file)
@@ -2190,7 +2190,7 @@ static int show_one_reflog_ent(struct files_ref_store *refs,
        char *email_end, *message;
        timestamp_t timestamp;
        int tz;
-       const char *p = sb->buf;
+       char *p = sb->buf;
 
        /* old SP new SP name <email> SP time TAB msg LF */
        if (!sb->len || sb->buf[sb->len - 1] != '\n' ||