[PATCH] ref-filter: don't declare a strdup'd variable const before writing to it
- From
Collin Funk <collin.funk1@gmail.com>
- Date
- Feb 14, 2026, 05:15 UTC
- Message-ID
- <c752a4a6c750bc485804b43d7b525754e39e5fe0.1771046151.git.collin.funk1@gmail.com>
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