From: Junio C Hamano <gitster@pobox.com>
To: Zejun Zhao <jelly.zhao.42@gmail.com>
Cc: git@vger.kernel.org, Elijah Newren <newren@gmail.com>,
Patrick Steinhardt <ps@pks.im>
Subject: Re: [GSOC][PATCH] apply: address -Wsign-comparison warnings
Date: Wed, 05 Feb 2025 04:58:57 -0800 [thread overview]
Message-ID: <xmqqh658r1im.fsf@gitster.g> (raw)
In-Reply-To: <20250205014055.737190-1-jelly.zhao.42@gmail.com> (Zejun Zhao's message of "Wed, 5 Feb 2025 01:40:55 +0000")
> @@ -1087,11 +1086,11 @@ static int gitdiff_index(struct gitdiff_data *state,
> * and optional space with octal mode.
> */
> const char *ptr, *eol;
> - int len;
> - const unsigned hexsz = the_hash_algo->hexsz;
> + size_t len;
> + const size_t hexsz = the_hash_algo->hexsz;
I thought that I already saw this discussed in another thread.
The .hexsz of any hash algorithm would never be larger than what a
platform natural "unsigned" integer type can hold, so using size_t
for the member _is_ the wrong thing to do and the fix may be the
other way around, no?
There are genuinely good changes (correcting assigned variable from
int to size_t when the value ultimately came from a system function
that returns size_t) in this patch, but there are other annoying
ones like these, so I am not sure.
> ptr = strchr(line, '.');
> - if (!ptr || ptr[1] != '.' || hexsz < ptr - line)
> + if (!ptr || ptr[1] != '.' || hexsz < (size_t) (ptr - line))
Is this about -Wsign-compare complaining about size_t vs ptrdiff_t?
> @@ -1207,7 +1206,7 @@ static char *git_header_name(int p_value,
> cp = skip_tree_prefix(p_value, second, line + llen - second);
> if (!cp)
> goto free_and_fail1;
> - if (line + llen - cp != first.len ||
> + if ((size_t) (line + llen - cp) != first.len ||
Ditto.
> - if (len < second - name &&
> + if (len < (size_t) (second - name) &&
Ditto.
I said this before, but I am not sure if being strict about
"-Wsign-compare" is really buying us much. If we are getting so
many false positives that need to be squelched by churning the code
with so many typecasts in order to find a new and real problem,
is it really worth it?
next prev parent reply other threads:[~2025-02-05 12:59 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 1:40 [GSOC][PATCH] apply: address -Wsign-comparison warnings Zejun Zhao
2025-02-05 7:47 ` Patrick Steinhardt
2025-02-05 15:42 ` Zejun Zhao
2025-02-05 12:58 ` Junio C Hamano [this message]
2025-02-05 16:49 ` Zejun Zhao
2025-02-09 8:12 ` [GSOC][PATCH v2 0/6] " Zejun Zhao
2025-02-09 8:12 ` [GSOC][PATCH v2 1/6] apply: change fields in `apply_state` to unsigned Zejun Zhao
2025-02-13 9:51 ` Karthik Nayak
2025-02-13 18:39 ` Junio C Hamano
2025-02-09 8:12 ` [GSOC][PATCH v2 2/6] apply: change some variables from `int` to `size_t` Zejun Zhao
2025-02-13 6:08 ` Patrick Steinhardt
2025-02-16 7:12 ` [GSOC][PATCH] apply: address -Wsign-comparison warnings Zejun Zhao
2025-02-18 17:49 ` Junio C Hamano
2025-02-21 6:37 ` Zejun Zhao
2025-02-21 17:11 ` Junio C Hamano
2025-02-23 17:36 ` Zejun Zhao
2025-02-24 14:27 ` Junio C Hamano
2025-02-25 3:24 ` Zejun Zhao
2025-02-25 12:53 ` Junio C Hamano
2025-02-09 8:12 ` [GSOC][PATCH v2 3/6] apply: do a typecast to eliminate warnings Zejun Zhao
2025-02-09 8:12 ` [GSOC][PATCH v2 4/6] apply: cast some ptrdiff_t's to size_t's Zejun Zhao
2025-02-09 8:12 ` [GSOC][PATCH v2 5/6] apply: use `size_t` loop counters Zejun Zhao
2025-02-13 6:08 ` Patrick Steinhardt
2025-02-09 8:12 ` [GSOC][PATCH v2 6/6] apply: enable -Wsign-comparison checks Zejun Zhao
2025-02-16 7:28 ` [GSOC][PATCH v3 0/6] apply: address -Wsign-comparison warnings Zejun Zhao
2025-02-16 7:28 ` [PATCH v3 1/6] apply: correct type misuse in `apply.h` Zejun Zhao
2025-02-16 7:28 ` [PATCH v3 2/6] apply: change some variables from `int` to `size_t` Zejun Zhao
2025-02-16 7:28 ` [PATCH v3 3/6] apply: do a typecast to eliminate warnings Zejun Zhao
2025-02-16 7:28 ` [PATCH v3 4/6] apply: cast some ptrdiff_t's to size_t's Zejun Zhao
2025-02-16 7:28 ` [PATCH v3 5/6] apply: use `size_t` loop counters Zejun Zhao
2025-02-16 7:28 ` [PATCH v3 6/6] apply: enable -Wsign-comparison checks Zejun Zhao
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=xmqqh658r1im.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jelly.zhao.42@gmail.com \
--cc=newren@gmail.com \
--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).