From: Junio C Hamano <gitster@pobox.com>
To: Tuomas Ahola <taahol@utu.fi>
Cc: <git@vger.kernel.org>, Karthik Nayak <karthik.188@gmail.com>
Subject: Re: [PATCH v2] bulk-checkin: fix sign compare warnings
Date: Sun, 23 Mar 2025 15:08:03 -0700 [thread overview]
Message-ID: <xmqqo6xrqu2k.fsf@gitster.g> (raw)
In-Reply-To: <20250321221404.10727-1-taahol@utu.fi> (Tuomas Ahola's message of "Sat, 22 Mar 2025 00:14:04 +0200")
Tuomas Ahola <taahol@utu.fi> writes:
> In file bulk-checkin.c, three warnings are emitted by
> "-Wsign-compare", two of which are caused by trivial loop iterator
> type mismatches. The third one is also an uncomplicated case for
> which a simple cast is a safe and sufficient action as the variable in
> question only holds positive values (from sizeof() expression).
The point of the sign-compare is that a positive value that is
assigned to a signed variable may wrap around to become negative,
causing a comparison with an unsigned type with the same size to
fail.
So "only holds positive" is not a good enough explanation for the
reason why this workaround for the "-Wsign-compare" false-positive [*]
does not make things too bad. The key thing is that the value
assigned to this "ssize_t rsize" variable is a small non-negative
value that can fit both size_t and ssize_t.
[Footnote]
* If we take -Wsign-compare too literally, it is warning every time
a signed quantity and an unsigned quantity is being compared, so
we could argue that there is no false-positive. But that is an
obviously pretty useless warning, when we can trivially tell that
the value in a signed variable cannot have wrapped around.
next prev parent reply other threads:[~2025-03-23 22:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 20:07 [PATCH] bulk-checkin: fix sign compare warnings Tuomas Ahola
2025-03-21 21:08 ` Karthik Nayak
2025-03-21 22:14 ` [PATCH v2] " Tuomas Ahola
2025-03-23 22:08 ` Junio C Hamano [this message]
2025-03-24 2:53 ` [PATCH] " Jeff King
2025-03-24 19:48 ` Karthik Nayak
2025-03-24 20:13 ` Jeff King
2025-03-24 21:47 ` [PATCH v3] " Tuomas Ahola
2025-03-24 23:46 ` Jeff King
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=xmqqo6xrqu2k.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=taahol@utu.fi \
/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).