From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Giuseppe Bilotta" <giuseppe.bilotta@gmail.com>
Cc: git@vger.kernel.org, Jim Meyering <jim@meyering.net>,
Fredrik Gustafsson <iveqy@iveqy.com>
Subject: Re: [PATCH 1/3] apply: get rid of useless x < 0 comparison on a size_t type
Date: Sun, 06 Nov 2011 10:35:42 -0800 [thread overview]
Message-ID: <7vsjm15cap.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1320581184-4557-2-git-send-email-avarab@gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Sun, 6 Nov 2011 13:06:22 +0100")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> According to the C standard size_t is always unsigned, therefore the
> comparison "n1 < 0 || n2 < 0" when n1 and n2 are size_t will always be
> false.
>
> This was raised by clang 2.9 which throws this warning when compiling
> apply.c:
>
> builtin/apply.c:253:9: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
> if (n1 < 0 || n2 < 0)
> ~~ ^ ~
> builtin/apply.c:253:19: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
> if (n1 < 0 || n2 < 0)
> ~~ ^ ~
>
> This check was originally added in v1.6.5-rc0~53^2 by Giuseppe Bilotta
> while adding an option to git-apply to ignore whitespace differences.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
I agree that these quantities can never be negative, so I'll apply the
patch as is.
But I have this suspicion that this was a rather sloppy defensive check to
protect this codepath against potential breakage in another codepath (most
likely update_pre_post_images() touched by the same patch) that adjusts
image->line[].len the caller of this function uses to feed these two
parameters. Giuseppe may have been not confident enough that the code
added to that function ensures not to undershoot when it reduces "len", or
something.
Giuseppe, can you explain what is going on?
Thanks
> builtin/apply.c | 3 ---
> 1 files changed, 0 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/apply.c b/builtin/apply.c
> index 84a8a0b..b3b59db 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -250,9 +250,6 @@ static int fuzzy_matchlines(const char *s1, size_t n1,
> const char *last2 = s2 + n2 - 1;
> int result = 0;
>
> - if (n1 < 0 || n2 < 0)
> - return 0;
> -
> /* ignore line endings */
> while ((*last1 == '\r') || (*last1 == '\n'))
> last1--;
next prev parent reply other threads:[~2011-11-06 18:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-06 12:06 [PATCH 0/3] Fix code issues spotted by clang Ævar Arnfjörð Bjarmason
2011-11-06 12:06 ` [PATCH 1/3] apply: get rid of useless x < 0 comparison on a size_t type Ævar Arnfjörð Bjarmason
2011-11-06 18:35 ` Junio C Hamano [this message]
2011-11-07 19:09 ` Giuseppe Bilotta
2011-11-06 12:06 ` [PATCH 2/3] diff/apply: cast variable in call to free() Ævar Arnfjörð Bjarmason
2011-11-06 12:06 ` [PATCH 3/3] grep: get rid of useless x < 0 comparison on an enum member Ævar Arnfjörð Bjarmason
2011-11-06 15:03 ` Andreas Schwab
2011-11-07 12:42 ` Ævar Arnfjörð Bjarmason
2011-11-07 13:12 ` Andreas Schwab
2011-11-07 16:38 ` Jeff King
2011-11-07 18:24 ` Andreas Schwab
2011-11-07 18:34 ` Jeff King
2011-11-07 18:55 ` Jeff King
2011-11-07 19:06 ` Ævar Arnfjörð Bjarmason
2011-11-07 20:13 ` Andreas Schwab
2011-11-07 19:49 ` Jonathan Nieder
2011-11-07 21:18 ` Junio C Hamano
2011-11-07 21:32 ` Jonathan Nieder
2011-11-07 21:48 ` Junio C Hamano
2011-11-07 22:21 ` Jonathan Nieder
2011-11-06 12:33 ` [PATCH 0/3] Fix code issues spotted by clang Ævar Arnfjörð Bjarmason
2011-11-08 16:05 ` Elijah Newren
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=7vsjm15cap.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=giuseppe.bilotta@gmail.com \
--cc=iveqy@iveqy.com \
--cc=jim@meyering.net \
/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).