git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Sören Krecker" <soekkle@freenet.de>, git@vger.kernel.org
Subject: Re: [PATCH 1/4] add-patch: Fix type missmatch rom msvc
Date: Fri, 27 Dec 2024 11:16:09 +0100	[thread overview]
Message-ID: <Z25-aaS7s3baU7ly@pks.im> (raw)
In-Reply-To: <xmqq34iaxh7r.fsf@gitster.g>

On Thu, Dec 26, 2024 at 01:33:12PM -0800, Junio C Hamano wrote:
> Sören Krecker <soekkle@freenet.de> writes:
> > @@ -1624,10 +1629,11 @@ static int patch_update_file(struct add_p_state *s,
> >  			else if (0 < response && response <= file_diff->hunk_nr)
> >  				hunk_index = response - 1;
> >  			else
> > -				err(s, Q_("Sorry, only %d hunk available.",
> > -					  "Sorry, only %d hunks available.",
> > -					  file_diff->hunk_nr),
> > -				    (int)file_diff->hunk_nr);
> > +				err(s,
> > +				    Q_("Sorry, only %"PRIuMAX" hunk available.",
> > +				       "Sorry, only %"PRIuMAX" hunks available.",
> > +				       (uintmax_t)file_diff->hunk_nr),
> > +				    (uintmax_t)file_diff->hunk_nr);
> 
> Again, this hunk may be needed, as the "hunk_nr" uses size_t, which
> probably is overly wide.
> 
> So, I do not mind too much to adjust the code around hunk_nr,
> hunk_alloc and other things that are already size_t (but before
> doing so, we probably should see if it makes more sense to use ulong
> for these members instead of size_t), hbut I am not sure if it is a
> sensible move to change old_offset, count, etc. that count in number
> of lines and use ulong (not bytes) to use size_t instead.
> 
> size_t _might_ be wider than some other forms of unsigned integers,
> but it is not necessarily the widest, so "because on msvc ulong is
> merely 32-bit and I want wider integer like everybody else!" is not
> a good excuse for such a change (if it were, we'd all coding with
> nothing but uintmax_t).
> 
> So I dunno.

In practice, the number of bytes and number of lines _can_ be the same
when the file consists of newlines, only. That is of course unlikely to
be the case in any sane input, but may be the case when processing input
that was specifically crafted to trigger such an edge case. So using a
type that can store the maximum size of a theoretically possible object
feels like a sensible safeguard to me and requires us to worry less
about such weird edge cases.

I also doubt that widening the type to `size_t` would have a meaningful
impact on performance, so I don't see a strong reason not to go there.
I tend to think that using `size_t` in such size-like-fields should be
our default unless there is a good reason not to pick it.

Patrick

  reply	other threads:[~2024-12-27 10:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-23 11:04 [PATCH 0/4] Fixes typemissmatch warinigs from msvc Sören Krecker
2024-12-23 11:04 ` [PATCH 1/4] add-patch: Fix type missmatch rom msvc Sören Krecker
2024-12-26 21:33   ` Junio C Hamano
2024-12-27 10:16     ` Patrick Steinhardt [this message]
2024-12-27 10:38     ` Phillip Wood
2024-12-27 14:31       ` Junio C Hamano
2024-12-27 16:35         ` Sören Krecker
2024-12-27 16:42           ` Junio C Hamano
2024-12-28 16:04         ` Phillip Wood
2024-12-23 11:04 ` [PATCH 2/4] date.c: Fix type missmatch warings from msvc Sören Krecker
2024-12-26 21:34   ` Junio C Hamano
2024-12-23 11:04 ` [PATCH 3/4] apply.c : " Sören Krecker
2024-12-23 11:04 ` [PATCH 4/4] commit.c: " Sören Krecker
2024-12-26 21:38   ` Junio C Hamano
2024-12-23 16:37 ` [PATCH 0/4] Fixes typemissmatch warinigs " Junio C Hamano
2024-12-23 16:52   ` Junio C Hamano
2024-12-26  8:59     ` Sören Krecker

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=Z25-aaS7s3baU7ly@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=soekkle@freenet.de \
    /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).