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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 17, 2025 at 12:49:33PM -0700, Karthik Nayak wrote:

> > 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux