git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] bulk-checkin: fix sign compare warnings

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 23, 2025, 22:08 UTC
Message-ID
<xmqqo6xrqu2k.fsf@gitster.g>
In-Reply-To
<20250321221404.10727-1-taahol@utu.fi>
Tuomas Ahola <taahol@utu.fi> writes:
Show 5 quoted lines
> 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.
Previous: Tuomas AholaNext: Jeff King
Message 4 of 9 in “bulk-checkin: fix sign compare warnings”
  1. bulk-checkin: fix sign compare warningsTuomas Ahola, Mar 21, 2025
  2. Karthik NayakMar 21, 2025
  3. bulk-checkin: fix sign compare warningsTuomas Ahola, Mar 21, 2025
  4. Junio C HamanoMar 23, 2025
  5. Jeff KingMar 24, 2025
  6. Karthik NayakMar 24, 2025
  7. Jeff KingMar 24, 2025
  8. bulk-checkin: fix sign compare warningsTuomas Ahola, Mar 24, 2025
  9. Jeff KingMar 24, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.