From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: "Sören Krecker" <soekkle@freenet.de>,
git@vger.kernel.org, "Patrick Steinhardt" <ps@pks.im>
Subject: Re: [PATCH 1/4] add-patch: Fix type missmatch rom msvc
Date: Fri, 27 Dec 2024 06:31:40 -0800 [thread overview]
Message-ID: <xmqq5xn5urhv.fsf@gitster.g> (raw)
In-Reply-To: <e396131c-1bd3-46d0-bae6-cd97ca9710d8@gmail.com> (Phillip Wood's message of "Fri, 27 Dec 2024 10:38:33 +0000")
Phillip Wood <phillip.wood123@gmail.com> writes:
>>> struct hunk_header {
>>> - unsigned long old_offset, old_count, new_offset, new_count;
>>> + size_t old_offset, old_count, new_offset, new_count;
>> These are not "size"s in the traditional sense of what size_t is
>> (i.e. the number of bytes in a region of memory), but are more or
>> less proportional to that in that they count in number of lines.
>> If ulong is sufficient to count number of lines in an incoming
>> patch, then turning size_t may be excessive---are we sure that we
>> are not unnecessarily using wider-than-necessary size_t in some
>> places to hold these values for which ulong is sufficient, causing
>> compilers to emit unnecessary warning?
>
> That's my thought too - I think something like the diff below should
> fix the warnings by using more appropriate types in expressions
> involving the hunk header offset and count. Our internal diff
> implementation will not generate diffs for blobs greater than ~1GB
> and I don't think "git apply" can handle diff headers that contain
> numbers greater that ULONG_MAX so switching to size_t here seems
> unnecessary.
Yes, exactly.
Of course, when filling old_offset and friends by parsing an input
line like this:
@@ -253,7 +253,7 @@ struct hunk_header {
it would be a bug if we did not check if "253" overflows the type of
old_offset, etc. And I would very much welcome patches to fix such
a careless input validation routine. But replacing ulong with size_t
would not make such a problem go away.
Now, I would be a bit more sympathetic if the patch were to use
integers of exact sizes, in the name of "let's make sure that
regardless of the platforms we handle patches up to the same limit".
But size_t is not a type that is appropriate for that (and of course
ulong is not, either---but the original did not aim for such a uniform
limit to begin with).
> @@ -1626,7 +1628,7 @@ static int patch_update_file(struct add_p_state *s,
> else
> err(s, Q_("Sorry, only %d hunk available.",
> "Sorry, only %d hunks available.",
> - file_diff->hunk_nr),
> + (int)file_diff->hunk_nr),
> (int)file_diff->hunk_nr);
> } else if (s->answer.buf[0] == '/') {
> regex_t regex;
I skimmed your "how about going this way" illustration patch and
found all the hunks reasonable, but this one I am not sure. Is
there a reason why hunk_nr has to be of type size_t?
When queuing a hunk (and performing an operation that changes the
number of hunks, like splitting an existing one), the code should be
careful not to make too many hunks to overflow "int" (if that is the
more natural type to count them---and "int" being the most natural
integer type for the platform, I tend to think it should be fine),
again, that applies equally if the type of hunk_nr is "size_t".
Thanks.
next prev parent reply other threads:[~2024-12-27 14:31 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
2024-12-27 10:38 ` Phillip Wood
2024-12-27 14:31 ` Junio C Hamano [this message]
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=xmqq5xn5urhv.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood123@gmail.com \
--cc=ps@pks.im \
--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).