From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, Phillip Wood <phillip.wood123@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH v3] diff: check range before dereferencing an array element
Date: Tue, 29 Apr 2025 15:37:35 -0700 [thread overview]
Message-ID: <xmqqldri4ms0.fsf@gitster.g> (raw)
In-Reply-To: <20250429215847.GB36727@coredump.intra.peff.net> (Jeff King's message of "Tue, 29 Apr 2025 17:58:47 -0400")
Jeff King <peff@peff.net> writes:
>> @@ -892,7 +892,7 @@ static void fill_es_indent_data(struct emitted_diff_symbol *es)
>>
>> /* skip any \v \f \r at start of indentation */
>> while (s[off] == '\f' || s[off] == '\v' ||
>> - (s[off] == '\r' && off < len - 1))
>> + (off < len - 1 && s[off] == '\r'))
>> off++;
>
> ...since the same pattern exists for the other s[off] checks, is it
> worth future-proofing this like:
>
> while (off < len - 1 &&
> (s[off] == '\f' || s[off] == '\v' || s[off] == '\r')
>
> ?
But doesn't it change the semantics?
s[off] == '\f', even if off is at the end of the string, i.e. (off
== len - 1), must trigger the off++ increment.
On the other hand, CR that is the part of CRLF at the end of line is
*not* treated like other funny whitespace control characters. This
"is off not at the end of line, if so check CR" comparison is about
that.
next prev parent reply other threads:[~2025-04-29 22:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 17:26 [PATCH 0/2] Range-check array index before access Johannes Schindelin via GitGitGadget
2025-03-26 17:26 ` [PATCH 1/2] diff: check range before dereferencing an array element Johannes Schindelin via GitGitGadget
2025-03-27 11:01 ` Junio C Hamano
2025-03-27 14:59 ` Phillip Wood
2025-03-26 17:26 ` [PATCH 2/2] read-cache: " Johannes Schindelin via GitGitGadget
2025-03-26 18:02 ` Jeff King
2025-03-27 11:05 ` [PATCH v2 0/2] Range-check array index before access Johannes Schindelin via GitGitGadget
2025-03-27 11:05 ` [PATCH v2 1/2] diff: check range before dereferencing an array element Johannes Schindelin via GitGitGadget
2025-03-28 2:54 ` Junio C Hamano
2025-03-27 11:05 ` [PATCH v2 2/2] read-cache: " Johannes Schindelin via GitGitGadget
2025-03-28 5:49 ` Jeff King
2025-04-11 14:50 ` Junio C Hamano
2025-04-29 11:37 ` [PATCH v3] diff: " Johannes Schindelin via GitGitGadget
2025-04-29 19:39 ` Junio C Hamano
2025-04-29 21:58 ` Jeff King
2025-04-29 22:37 ` Junio C Hamano [this message]
2025-04-29 23:33 ` Jeff King
2025-04-29 23:46 ` Junio C Hamano
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=xmqqldri4ms0.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johannes.schindelin@gmx.de \
--cc=peff@peff.net \
--cc=phillip.wood123@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.