From: Arnav Bhate <bhatearnav@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [GSoC PATCH] rm: fix sign comparison warnings
Date: Thu, 13 Mar 2025 19:56:45 +0530 [thread overview]
Message-ID: <a4d33c35-a6c3-4f42-84c7-80a7ecdcbf96@gmail.com> (raw)
In-Reply-To: <xmqqy0x9s8mg.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
> Arnav Bhate <bhatearnav@gmail.com> writes:
>
>> static int get_ours_cache_pos(const char *path, int pos)
>> {
>> - int i = -pos - 1;
>> + /*
>> + * This function is only called when pos < 0, so -pos - 1 is
>> + * greater than or equal to 0, so it can be safely be stored in
>> + * an unsigned int.
>> + */
>> + unsigned int i = -pos - 1;
>
> "Can be safely stored", sure.
>
> But so is "int i" perfectly adequate to hold such a value, no?
>
> This is one of the many instances that demonstrate why the
> "-Wsign-compare" warning is of dubious value, and invites worse code
> than necessary.
While "int i" may be adequate, this, in my opinion, emphasises the fact
that we do not want i to take negative values, so I do not think this is
worse. Karthik's suggestion in another reply is also an alternative.
>> @@ -58,7 +62,7 @@ static void print_error_files(struct string_list *files_list,
>> int *errs)
>> {
>> if (files_list->nr) {
>> - int i;
>> + unsigned int i;
>> struct strbuf err_msg = STRBUF_INIT;
>>
>> strbuf_addstr(&err_msg, main_msg);
>> @@ -271,6 +275,7 @@ int cmd_rm(int argc,
>> {
>> struct lock_file lock_file = LOCK_INIT;
>> int i, ret = 0;
>> + unsigned int j;
>> struct pathspec pathspec;
>> char *seen;
>>
>> @@ -314,8 +319,8 @@ int cmd_rm(int argc,
>> if (pathspec_needs_expanded_index(the_repository->index, &pathspec))
>> ensure_full_index(the_repository->index);
>>
>> - for (i = 0; i < the_repository->index->cache_nr; i++) {
>> - const struct cache_entry *ce = the_repository->index->cache[i];
>> + for (j = 0; j < the_repository->index->cache_nr; j++) {
>> + const struct cache_entry *ce = the_repository->index->cache[j];
>>
>> if (!include_sparse &&
>> (ce_skip_worktree(ce) ||
--
Regards,
Arnav Bhate
(He/Him)
next prev parent reply other threads:[~2025-03-13 14:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-12 20:19 [GSoC PATCH] rm: fix sign comparison warnings Arnav Bhate
2025-03-13 7:16 ` Junio C Hamano
2025-03-13 11:25 ` Karthik Nayak
2025-03-13 14:30 ` Arnav Bhate
2025-03-13 14:45 ` Karthik Nayak
2025-03-13 15:25 ` Junio C Hamano
2025-03-13 14:26 ` Arnav Bhate [this message]
2025-03-16 10:13 ` [GSoC PATCH v2] " Arnav Bhate
2025-03-17 16:47 ` Junio C Hamano
2025-03-17 17:05 ` Arnav Bhate
2025-03-17 17:07 ` [GSoC PATCH v3] " Arnav Bhate
2025-03-17 17:12 ` Arnav Bhate
2025-03-17 17:10 ` Arnav Bhate
2025-03-29 6:03 ` [GSoC PATCH v4] " Arnav Bhate
2025-03-29 6:07 ` Arnav Bhate
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=a4d33c35-a6c3-4f42-84c7-80a7ecdcbf96@gmail.com \
--to=bhatearnav@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).