git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: shejialuo <shejialuo@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH 7/9] builtin/log: fix remaining -Wsign-compare warnings
Date: Fri, 27 Dec 2024 22:03:39 +0800	[thread overview]
Message-ID: <Z26zu7X7VCSX3yn9@ArchLinux> (raw)
In-Reply-To: <Z26yPlLMlxyecZVk@pks.im>

On Fri, Dec 27, 2024 at 02:57:18PM +0100, Patrick Steinhardt wrote:
> On Fri, Dec 27, 2024 at 09:21:56PM +0800, shejialuo wrote:
> > On Fri, Dec 27, 2024 at 11:46:27AM +0100, Patrick Steinhardt wrote:
> > > @@ -717,14 +715,14 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
> > >  	unsigned long size;
> > >  	enum object_type type;
> > >  	char *buf = repo_read_object_file(the_repository, oid, &type, &size);
> > > -	int offset = 0;
> > > +	unsigned long offset = 0;
> > 
> > Why here we use `unsigned long`, is this a special situation where we
> > cannot use `size_t`?
> 
> Mostly because other variables already use `unsigned long` here,
> including `repo_read_object_file()`. So given that our object layer
> doesn't support `size_t` it wouldn't make sense to use it for the
> offset, either.
> 

Make sense. Thanks for the explanation.

> > >  
> > >  	if (!buf)
> > >  		return error(_("could not read object %s"), oid_to_hex(oid));
> > >  
> > >  	assert(type == OBJ_TAG);
> > >  	while (offset < size && buf[offset] != '\n') {
> > > -		int new_offset = offset + 1;
> > > +		unsigned long new_offset = offset + 1;
> > >  		const char *ident;
> > >  		while (new_offset < size && buf[new_offset++] != '\n')
> > >  			; /* do nothing */
> > 
> > > @@ -2183,7 +2182,7 @@ int cmd_format_patch(int argc,
> > >  		fmt_patch_suffix = cfg.fmt_patch_suffix;
> > >  
> > >  	/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
> > > -	if (cfg.log.fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
> > > +	if (cfg.log.fmt_patch_name_max <= cast_size_t_to_int(strlen("0000-") + strlen(fmt_patch_suffix)))
> > 
> > A design question, why we don't change the type of
> > `cfg.log.fmt_patch_name_max` to be `size_t`?
> 
> The whole infra around this uses `int`s, too, so changing this variable
> here alone wouldn't suffice. We'd also have to adapt option handling,
> config handling, `struct rev_info::patch_name_max` and other bits and
> pieces. So in the end the size of required changes would likely balloon
> and thus I decided to not go down this rabbit hole.
> 

Yes, I agree. If we do this, there is a lot of efforts we need to deal
with.

> Patrick

  reply	other threads:[~2024-12-27 14:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-27 10:46 [PATCH 0/9] commit-reach: -Wsign-compare follow-ups Patrick Steinhardt
2024-12-27 10:46 ` [PATCH 1/9] prio-queue: fix type of `insertion_ctr` Patrick Steinhardt
2024-12-27 14:36   ` Jeff King
2024-12-27 10:46 ` [PATCH 2/9] commit-reach: fix index used to loop through unsigned integer Patrick Steinhardt
2024-12-27 14:46   ` Jeff King
2024-12-27 10:46 ` [PATCH 3/9] commit-reach: fix type of `min_commit_date` Patrick Steinhardt
2024-12-27 10:46 ` [PATCH 4/9] commit-reach: use `size_t` to track indices in `remove_redundant()` Patrick Steinhardt
2025-01-03  1:46   ` Justin Tobler
2024-12-27 10:46 ` [PATCH 5/9] commit-reach: use `size_t` to track indices in `get_reachable_subset()` Patrick Steinhardt
2024-12-27 10:46 ` [PATCH 6/9] builtin/log: use `size_t` to track indices Patrick Steinhardt
2025-01-03  1:58   ` Justin Tobler
2025-01-03  6:43     ` Patrick Steinhardt
2024-12-27 10:46 ` [PATCH 7/9] builtin/log: fix remaining -Wsign-compare warnings Patrick Steinhardt
2024-12-27 13:21   ` shejialuo
2024-12-27 13:57     ` Patrick Steinhardt
2024-12-27 14:03       ` shejialuo [this message]
2024-12-27 10:46 ` [PATCH 8/9] shallow: fix " Patrick Steinhardt
2024-12-27 10:46 ` [PATCH 9/9] commit-reach: use `size_t` to track indices when computing merge bases Patrick Steinhardt
2025-01-03  2:08   ` Justin Tobler
2025-01-03  6:43     ` Patrick Steinhardt
2024-12-27 19:47 ` [PATCH 0/9] commit-reach: -Wsign-compare follow-ups Junio C Hamano
2024-12-27 20:08   ` Junio C Hamano
2024-12-27 21:37     ` Jeff King
2024-12-28  8:41       ` Patrick Steinhardt
2024-12-28  0:00     ` Junio C Hamano
2024-12-28  8:27       ` Patrick Steinhardt
2024-12-28 15:38         ` Junio C Hamano
2024-12-28 19:05         ` racy leak sanitizer builds, was " Jeff King
2024-12-28 19:23           ` Jeff King
2024-12-28 19:31             ` Jeff King
2024-12-29 12:02             ` René Scharfe
2024-12-29 16:57               ` Jeff King
2024-12-30  4:32                 ` Jeff King
2024-12-30 13:46                 ` Junio C Hamano

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=Z26zu7X7VCSX3yn9@ArchLinux \
    --to=shejialuo@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --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).