Skip to contentSkip to conversation

convert: constify some variables in ident_to_worktree()

PATCH New Collin Funk 1 participant 1 message Mar 10

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 convert: constify some variables in ident_to_worktree()

When building with glibc-2.43 there is the following warnings:

convert.c: In function ‘ident_to_worktree’:
convert.c:1189:24: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1189 | dollar = memchr(src, '$', len);
| ^
convert.c:1212:32: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1212 | dollar = memchr(src + 3, '$', len - 3);
| ^
convert.c:1223:29: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1223 | spc = memchr(src + 4, ' ', dollar - src - 4);
| ^

The "dollar" and "space" pointers are used to iterate over the const string "src". Since they are never written to we can make them const too.

---
 convert.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
convert.c +2 -1
index a34ec6ecdc..eae36c8a59 100644
@@ -1168,7 +1168,8 @@ static int ident_to_worktree(const char *src, size_t len,
 			     struct strbuf *buf, int ident)
 {
 	struct object_id oid;
-	char *to_free = NULL, *dollar, *spc;
+	char *to_free = NULL;
+	const char *dollar, *spc;
 	int cnt;
 
 	if (!ident)
Signature · 1 line
2.53.0