Thread (44 messages) 44 messages, 5 authors, 2025-07-17

Re: [PATCH v5 3/5] refs: selectively set prefix in the seek functions

From: Jeff King <hidden>
Date: 2025-07-17 21:55:13

On Thu, Jul 17, 2025 at 12:49:33PM -0700, Karthik Nayak wrote:
quoted
diff --git a/refs/ref-cache.c b/refs/ref-cache.c
index 1d95b56d40..3949d145e8 100644
--- a/refs/ref-cache.c
+++ b/refs/ref-cache.c
@@ -498,13 +498,14 @@ static int cache_ref_iterator_seek(struct ref_iterator *ref_iterator,
 		 * indexing to each level as needed.
 		 */
 		do {
-			int len, idx;
+			size_t len;
+			int idx;
 			int cmp = 0;

 			sort_ref_dir(dir);

 			slash = strchr(slash, '/');
-			len = slash ? slash - refname : (int)strlen(refname);
+			len = slash ? slash - refname : strlen(refname);

 			for (idx = 0; idx < dir->nr; idx++) {
 				cmp = strncmp(refname, dir->entries[idx]->name, len);

-Peff
Thanks, I think we have to typecast `slash - refname` to size_t, but
this is the right way to do it. Thanks for the review!
Ah, yeah. I mistakenly test-compiled without DEVELOPER=1. ;)

I do think that cast is a lesser evil, though. It is a ptrdiff_t, but we
know it is correctly unsigned because "slash > refname" via strchr.  I
wish there was a good way to use the type system to tell the compiler
that.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help