From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 10/10] reftable: address trivial -Wsign-compare warnings
Date: Thu, 16 Jan 2025 14:12:33 -0800 [thread overview]
Message-ID: <xmqqldvapfvy.fsf@gitster.g> (raw)
In-Reply-To: <20250116-b4-pks-reftable-sign-compare-v1-10-bd30e2ee96e7@pks.im> (Patrick Steinhardt's message of "Thu, 16 Jan 2025 11:08:42 +0100")
Patrick Steinhardt <ps@pks.im> writes:
> Address the last couple of trivial -Wsign-compare warnings in the
> reftable library and remove the DISABLE_SIGN_COMPARE_WARNINGS macro that
> we have in "reftable/system.h".
Hmph.
> - int l = strlen(str);
> + size_t l = strlen(str);
Obviously correct.
> - j = 1;
> - while (j < count) {
> + for (uint64_t j = 1; j < count; j++) {
OK. As count is u64, it makes sense to match.
> diff --git a/reftable/stack.c b/reftable/stack.c
> index 531660a49f..5c0d6273a7 100644
> --- a/reftable/stack.c
> +++ b/reftable/stack.c
> @@ -220,9 +220,9 @@ void reftable_stack_destroy(struct reftable_stack *st)
> }
>
> if (st->readers) {
> - int i = 0;
> struct reftable_buf filename = REFTABLE_BUF_INIT;
> - for (i = 0; i < st->readers_len; i++) {
> +
> + for (size_t i = 0; i < st->readers_len; i++) {
Likewise, readers_len is size_t so counters can match it.
> - for (i = 0; i < st->readers_len; i++) {
> + for (size_t i = 0; i < st->readers_len; i++) {
Ditto.
> - for (i = 0; !found && i < st->readers_len; i++) {
> + for (size_t i = 0; !found && i < st->readers_len; i++)
Ditto.
> diff --git a/reftable/writer.c b/reftable/writer.c
> index 4e6ca2e368..91d6629486 100644
> --- a/reftable/writer.c
> +++ b/reftable/writer.c
> @@ -577,7 +577,7 @@ static int writer_finish_section(struct reftable_writer *w)
>
> struct common_prefix_arg {
> struct reftable_buf *last;
> - int max;
> + size_t max;
> };
This is dubious. write.c:update_common() uses this to keep track of
the maximum value returned by common_prefix_size(), which returns
an int. writer.c:writer_dump_object_index() assigns the value
comparable to this member to reftable_stats.object_id_len that is of
type int.
I may be more sympathetic if we were making common_prefix_size()
return size_t instead of "int" and dealing with all the fallouts
from such a change, but this smells more like somebody _else_ is
using size_t on something that is not an allocation size, and such
mixed use is cascading down to contaminate this member, which would
be perfectly fine with platform native "int".
Ah, OK, an earlier patch does change these other things to size_t,
so this must change to size_t to be consistent. Shouldn't it be
done in the same patch, then, though?
next prev parent reply other threads:[~2025-01-16 22:12 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-16 10:08 [PATCH 00/10] reftable: fix -Wsign-compare warnings Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 01/10] meson: stop disabling -Wsign-compare Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 02/10] reftable/record: drop unused `print` function pointer Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 03/10] reftable/record: handle overflows when decoding varints Patrick Steinhardt
2025-01-20 9:47 ` Karthik Nayak
2025-01-20 15:09 ` Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 04/10] reftable/basics: adjust `common_prefix_size()` to return `size_t` Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 05/10] reftable/basics: adjust `hash_size()` to return `uint32_t` Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 06/10] reftable/block: adapt header and footer size to return a `size_t` Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 07/10] reftable/block: adjust type of the restart length Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 08/10] reftable/blocksource: adjust type of the block length Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 09/10] reftable/blocksource: adjust `read_block()` to return `ssize_t` Patrick Steinhardt
2025-01-16 10:08 ` [PATCH 10/10] reftable: address trivial -Wsign-compare warnings Patrick Steinhardt
2025-01-16 22:12 ` Junio C Hamano [this message]
2025-01-17 6:10 ` Patrick Steinhardt
2025-01-20 10:07 ` [PATCH 00/10] reftable: fix " Karthik Nayak
2025-01-20 15:10 ` Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 " Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 01/10] meson: stop disabling -Wsign-compare Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 02/10] reftable/record: drop unused `print` function pointer Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 03/10] reftable/record: handle overflows when decoding varints Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 04/10] reftable/basics: adjust `common_prefix_size()` to return `size_t` Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 05/10] reftable/basics: adjust `hash_size()` to return `uint32_t` Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 06/10] reftable/block: adapt header and footer size to return a `size_t` Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 07/10] reftable/block: adjust type of the restart length Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 08/10] reftable/blocksource: adjust type of the block length Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 09/10] reftable/blocksource: adjust `read_block()` to return `ssize_t` Patrick Steinhardt
2025-01-20 16:17 ` [PATCH v2 10/10] reftable: address trivial -Wsign-compare warnings Patrick Steinhardt
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=xmqqldvapfvy.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--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).