git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zejun Zhao <jelly.zhao.42@gmail.com>
To: ps@pks.im
Cc: git@vger.kernel.org, gitster@pobox.com, jelly.zhao.42@gmail.com,
	newren@gmail.com
Subject: Re: [GSOC][PATCH] apply: address -Wsign-comparison warnings
Date: Wed,  5 Feb 2025 15:42:32 +0000	[thread overview]
Message-ID: <20250205154232.237380-1-jelly.zhao.42@gmail.com> (raw)
In-Reply-To: <Z6MXevArKhRLacAb@pks.im>

Thank you for reviewing this patch.

On Wed, Feb 05, 2025 08:47:06 +0100, Patrick Steinhardt wrote:
> You should split up this patch into a series, as it is really hard to
> follow what's going on. There are a couple of things happening:
> 
>   - You change types in `struct apply_state`, which bubbles up.
> 
>   - You adapt `git_hdr_len()` to receive different inputs, which bubbles
>     up.
> 
>   - You perform small fixes in several places.
> 
> It might also be a good idea to split out the loop counters into a
> separate commit, as those are trivially correct.

Sure I'll come up with a v2 patch series, in which each kind of fixes 
will be put in a single commit and I'll state why I believe the type 
cast/change is safe for every single fix in the commit message.

> > @@ -1087,11 +1086,11 @@ static int gitdiff_index(struct gitdiff_data *state,
> >  	 * and optional space with octal mode.
> >  	 */
> >  	const char *ptr, *eol;
> > -	int len;
> > -	const unsigned hexsz = the_hash_algo->hexsz;
> > +	size_t len;
> > +	const size_t hexsz = the_hash_algo->hexsz;
> 
> The change to `hexsz` shouldn't be needed, even if it makes us match the
> type of `hexsz` as declared in `git_hash_algo`.

Yes it's not necessary here to change the type. And for the `hexsz` stuff,
on Wed, Feb 05 2025 04:58:57 -0800, Junio C Hamano wrote,
> I thought that I already saw this discussed in another thread.
> 
> The .hexsz of any hash algorithm would never be larger than what a
> platform natural "unsigned" integer type can hold, so using size_t
> for the member _is_ the wrong thing to do and the fix may be the
> other way around, no?

I found the discussion mentioned at [1]. It seems like the change here 
only makes things worse so I'll see if I'd leave it untouched or change 
the type of `.hexsz` member to `int` or something.

[1] https://lore.kernel.org/git/xmqqttaqw2eb.fsf@gitster.g/

> > @@ -2185,7 +2182,7 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si
> >  			};
> >  			int i;
> 
> This may arguably be `size_t`, as well.

It's OK for me to use a `size_t` loop count everywhere but I tried to 
keep the changes in this patch minimal (forget about the `hexsz` thing).
I could apply this change if you insist.

> > @@ -2257,12 +2255,12 @@ static void show_stats(struct apply_state *state, struct patch *patch)
> >  	}
> >  
> >  	if (patch->is_binary) {
> > -		printf(" %-*s |  Bin\n", max, qname.buf);
> > +		printf(" %-*s |  Bin\n", (int) max, qname.buf);
> >  		strbuf_release(&qname);
> >  		return;
> >  	}
> >  
> > -	printf(" %-*s |", max, qname.buf);
> > +	printf(" %-*s |", (int) max, qname.buf);
> >  	strbuf_release(&qname);
> >  
> >  	/*
> 
> Do we _know_ that `max` fits into an `int`?

Yep we've set an upper bound for `max` before:
> /*
>  * "scale" the filename
>  */
> max = state->max_len;
> if (max > 50)
> 	      max = 50;
so it must fit into an `int`.

  reply	other threads:[~2025-02-05 15:45 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-05  1:40 [GSOC][PATCH] apply: address -Wsign-comparison warnings Zejun Zhao
2025-02-05  7:47 ` Patrick Steinhardt
2025-02-05 15:42   ` Zejun Zhao [this message]
2025-02-05 12:58 ` Junio C Hamano
2025-02-05 16:49   ` Zejun Zhao
2025-02-09  8:12 ` [GSOC][PATCH v2 0/6] " Zejun Zhao
2025-02-09  8:12   ` [GSOC][PATCH v2 1/6] apply: change fields in `apply_state` to unsigned Zejun Zhao
2025-02-13  9:51     ` Karthik Nayak
2025-02-13 18:39       ` Junio C Hamano
2025-02-09  8:12   ` [GSOC][PATCH v2 2/6] apply: change some variables from `int` to `size_t` Zejun Zhao
2025-02-13  6:08     ` Patrick Steinhardt
2025-02-16  7:12       ` [GSOC][PATCH] apply: address -Wsign-comparison warnings Zejun Zhao
2025-02-18 17:49         ` Junio C Hamano
2025-02-21  6:37           ` Zejun Zhao
2025-02-21 17:11             ` Junio C Hamano
2025-02-23 17:36               ` Zejun Zhao
2025-02-24 14:27                 ` Junio C Hamano
2025-02-25  3:24                   ` Zejun Zhao
2025-02-25 12:53                     ` Junio C Hamano
2025-02-09  8:12   ` [GSOC][PATCH v2 3/6] apply: do a typecast to eliminate warnings Zejun Zhao
2025-02-09  8:12   ` [GSOC][PATCH v2 4/6] apply: cast some ptrdiff_t's to size_t's Zejun Zhao
2025-02-09  8:12   ` [GSOC][PATCH v2 5/6] apply: use `size_t` loop counters Zejun Zhao
2025-02-13  6:08     ` Patrick Steinhardt
2025-02-09  8:12   ` [GSOC][PATCH v2 6/6] apply: enable -Wsign-comparison checks Zejun Zhao
2025-02-16  7:28 ` [GSOC][PATCH v3 0/6] apply: address -Wsign-comparison warnings Zejun Zhao
2025-02-16  7:28   ` [PATCH v3 1/6] apply: correct type misuse in `apply.h` Zejun Zhao
2025-02-16  7:28   ` [PATCH v3 2/6] apply: change some variables from `int` to `size_t` Zejun Zhao
2025-02-16  7:28   ` [PATCH v3 3/6] apply: do a typecast to eliminate warnings Zejun Zhao
2025-02-16  7:28   ` [PATCH v3 4/6] apply: cast some ptrdiff_t's to size_t's Zejun Zhao
2025-02-16  7:28   ` [PATCH v3 5/6] apply: use `size_t` loop counters Zejun Zhao
2025-02-16  7:28   ` [PATCH v3 6/6] apply: enable -Wsign-comparison checks Zejun Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250205154232.237380-1-jelly.zhao.42@gmail.com \
    --to=jelly.zhao.42@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).