public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ref-filter: don't declare a strdup'd variable const before writing to it
@ 2026-02-14  5:15 Collin Funk
  2026-02-15  8:57 ` [PATCH 0/4] cleaning up ref-filter lstrip/rstrip code Jeff King
  0 siblings, 1 reply; 14+ messages in thread
From: Collin Funk @ 2026-02-14  5:15 UTC (permalink / raw)
  To: git; +Cc: Collin Funk, Junio C Hamano

I generally don't like the casts like in rstrip_ref_components and
rstrip_ref_components because they force you to write this:

    free((char *)free_ptr);

And the const doesn't really benefit readability, in my opinion.

That is a bit of a seperate topic than fixing the warning, though, so
I left them as-is.

-- 8< --

With glibc-2.43 there is the following warning:

    ../ref-filter.c: In function ‘rstrip_ref_components’:
    ../ref-filter.c:2237:27: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
     2237 |                 char *p = strrchr(start, '/');
          |

We can remove the const from "start" since it is the result of strdup
and we end up writing to it through "p".

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
---
 ref-filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ref-filter.c b/ref-filter.c
index 3917c4ccd9..183cb6bbd7 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2214,7 +2214,7 @@ static const char *lstrip_ref_components(const char *refname, int len)
 static const char *rstrip_ref_components(const char *refname, int len)
 {
 	long remaining = len;
-	const char *start = xstrdup(refname);
+	char *start = xstrdup(refname);
 	const char *to_free = start;
 
 	if (len < 0) {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-02-22 17:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-14  5:15 [PATCH] ref-filter: don't declare a strdup'd variable const before writing to it Collin Funk
2026-02-15  8:57 ` [PATCH 0/4] cleaning up ref-filter lstrip/rstrip code Jeff King
2026-02-15  9:00   ` [PATCH 1/4] ref-filter: factor out refname component counting Jeff King
2026-02-17 18:07     ` Junio C Hamano
2026-02-19 11:21       ` Jeff King
2026-02-19 18:56         ` Junio C Hamano
2026-02-20  6:00           ` [PATCH] ref-filter: clarify lstrip/rstrip " Jeff King
2026-02-22 17:04         ` [PATCH 1/4] ref-filter: factor out refname " Karthik Nayak
2026-02-15  9:02   ` [PATCH 2/4] ref-filter: simplify lstrip_ref_components() memory handling Jeff King
2026-02-15  9:05   ` [PATCH 3/4] ref-filter: simplify rstrip_ref_components() " Jeff King
2026-02-15  9:07   ` [PATCH 4/4] ref-filter: avoid strrchr() in rstrip_ref_components() Jeff King
2026-02-16  7:23     ` Patrick Steinhardt
2026-02-15  9:11   ` [PATCH 0/4] cleaning up ref-filter lstrip/rstrip code Jeff King
2026-02-15 22:23   ` Collin Funk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox