git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 12/12] refs/files-backend: drop const to fix strchr() warning

From
Jeff King <peff@peff.net>
Date
Apr 2, 2026, 04:15 UTC
Message-ID
<20260402041516.GL3501239@coredump.intra.peff.net>
In-Reply-To
<20260402041433.GA3501120@coredump.intra.peff.net>

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>
---
 hex.c                | 6 +++---
 hex.h                | 6 ++++--
 refs/files-backend.c | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/hex.c b/hex.c
index 865a232167..bc756722ca 100644
--- 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 e9ccb54065..1e9a65d83a 100644
--- 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
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0537a72b2a..b3b0c25f84 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -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' ||
-- 
2.53.0.1172.ge9e20b5838
Previous: Jeff KingNext: Toon Claes
Message 49 of 50 in “fixing the remainder of the C23 strchr warnings”
  1. 0/12 fixing the remainder of the C23 strchr warningsJeff King, Mar 31, 2026
  2. 01/12 convert: add const to fix strchr() warningsJeff King, Mar 31, 2026
  3. 02/12 http: add const to fix strchr() warningsJeff King, Mar 31, 2026
  4. 03/12 transport-helper: drop const to fix strchr() warningsJeff King, Mar 31, 2026
  5. Patrick SteinhardtApr 1, 2026
  6. 04/12 pager: explicitly cast away strchr() constnessJeff King, Mar 31, 2026
  7. Junio C HamanoApr 1, 2026
  8. Jeff KingApr 2, 2026
  9. 05/12 run-command: explicitly cast away constness when assigning to voidJeff King, Mar 31, 2026
  10. 06/12 find_last_dir_sep(): convert inline function to macroJeff King, Mar 31, 2026
  11. 07/12 pseudo-merge: fix disk reads from find_pseudo_merge()Jeff King, Mar 31, 2026
  12. Jeff KingMar 31, 2026
  13. Junio C HamanoApr 1, 2026
  14. Taylor BlauApr 2, 2026
  15. 08/12 skip_prefix(): check const match between in and out paramsJeff King, Mar 31, 2026
  16. Phillip WoodApr 1, 2026
  17. Phillip WoodApr 1, 2026
  18. Jeff KingApr 1, 2026
  19. Junio C HamanoApr 1, 2026
  20. Phillip WoodApr 2, 2026
  21. Patrick SteinhardtApr 1, 2026
  22. 09/12 pkt-line: make packet_reader.line non-constJeff King, Mar 31, 2026
  23. Junio C HamanoApr 1, 2026
  24. Jeff KingApr 2, 2026
  25. 10/12 range-diff: drop const to fix strstr() warningsJeff King, Mar 31, 2026
  26. 11/12 http: drop const to fix strstr() warningJeff King, Mar 31, 2026
  27. 12/12 refs/files-backend: drop const to fix strchr() warningJeff King, Mar 31, 2026
  28. Patrick SteinhardtApr 1, 2026
  29. Junio C HamanoApr 1, 2026
  30. Jeff KingApr 2, 2026
  31. 0/12 fixing the remainder of the C23 strchr warningsJeff King, Apr 2, 2026
  32. 01/12 convert: add const to fix strchr() warningsJeff King, Apr 2, 2026
  33. 02/12 http: add const to fix strchr() warningsJeff King, Apr 2, 2026
  34. 03/12 transport-helper: drop const to fix strchr() warningsJeff King, Apr 2, 2026
  35. 04/12 pager: explicitly cast away strchr() constnessJeff King, Apr 2, 2026
  36. 05/12 run-command: explicitly cast away constness when assigning to voidJeff King, Apr 2, 2026
  37. 06/12 find_last_dir_sep(): convert inline function to macroJeff King, Apr 2, 2026
  38. 07/12 pseudo-merge: fix disk reads from find_pseudo_merge()Jeff King, Apr 2, 2026
  39. 08/12 skip_prefix(): check const match between in and out paramsJeff King, Apr 2, 2026
  40. Junio C HamanoApr 2, 2026
  41. Jeff KingApr 2, 2026
  42. Junio C HamanoApr 2, 2026
  43. Junio C HamanoApr 2, 2026
  44. Toon ClaesApr 3, 2026
  45. 13/12 git-compat-util: fix CONST_OUTPARAM typo and indentationJeff King, Apr 4, 2026
  46. 09/12 pkt-line: make packet_reader.line non-constJeff King, Apr 2, 2026
  47. 10/12 range-diff: drop const to fix strstr() warningsJeff King, Apr 2, 2026
  48. 11/12 http: drop const to fix strstr() warningJeff King, Apr 2, 2026
  49. 12/12 refs/files-backend: drop const to fix strchr() warningJeff King, Apr 2, 2026
  50. Toon ClaesApr 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.