Skip to content

Commit eafa1ad

Browse files
peffgitster
authored andcommitted
refs/files-backend: drop const to fix strchr() warning
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(). Note that unlike skip_prefix(), the function is not inline, so we can't just wrap it using the same name (otherwise the actual definition would expand the macro, which breaks compilation). So we rename the actual function with an "_impl" suffix, and callers will all use the macro. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b850c12 commit eafa1ad

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

hex.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ int get_oid_hex(const char *hex, struct object_id *oid)
5454
return get_oid_hex_algop(hex, oid, the_hash_algo);
5555
}
5656

57-
int parse_oid_hex_algop(const char *hex, struct object_id *oid,
58-
const char **end,
59-
const struct git_hash_algo *algop)
57+
int parse_oid_hex_algop_impl(const char *hex, struct object_id *oid,
58+
const char **end,
59+
const struct git_hash_algo *algop)
6060
{
6161
int ret = get_oid_hex_algop(hex, oid, algop);
6262
if (!ret)

hex.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ char *oid_to_hex(const struct object_id *oid); /* same static buffer */
4040
* other invalid character. end is only updated on success; otherwise, it is
4141
* unmodified.
4242
*/
43-
int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end,
44-
const struct git_hash_algo *algo);
43+
int parse_oid_hex_algop_impl(const char *hex, struct object_id *oid, const char **end,
44+
const struct git_hash_algo *algo);
45+
#define parse_oid_hex_algop(hex, oid, end, algo) \
46+
parse_oid_hex_algop_impl((hex), (oid), CONST_OUTPARAM((hex), (end)), (algo))
4547

4648
/*
4749
* These functions work like get_oid_hex and parse_oid_hex, but they will parse

refs/files-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@ static int show_one_reflog_ent(struct files_ref_store *refs,
21902190
char *email_end, *message;
21912191
timestamp_t timestamp;
21922192
int tz;
2193-
const char *p = sb->buf;
2193+
char *p = sb->buf;
21942194

21952195
/* old SP new SP name <email> SP time TAB msg LF */
21962196
if (!sb->len || sb->buf[sb->len - 1] != '\n' ||

0 commit comments

Comments
 (0)