Re: [PATCH] apply: keep buffer/size pair in sync when parsing binary hunks
- From
Carlo Arenas <carenas@gmail.com>
- Date
- Aug 10, 2021, 05:26 UTC
- Message-ID
- <CAPUEsphWN_-BWyfF9mnPhL56RSnmPZfmvh_QwhjoAb3xin8V-w@mail.gmail.com>
- In-Reply-To
- <YRHQAFDXs5xvyDND@coredump.intra.peff.net>
On Mon, Aug 9, 2021 at 9:24 PM Jeff King <peff@peff.net> wrote:
Show 10 quoted lines
> diff --git a/apply.c b/apply.c
> index 44bc31d6eb..4ed4b27169 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -1917,6 +1917,7 @@ static struct fragment *parse_binary_hunk(struct apply_state *state,
>
> state->linenr++;
> buffer += llen;
> + size -= llen;
> while (1) {Ironically, I was looking at this code because of your previous patch[1] that you suggested was ugly and because I was going to suggest moving from a for to a while loop to avoid the overly long line.
It is interesting to note though, that having a for (and obviously removing the last 2 lines from the loop) with a comma separated increment instead would have made this issue IMHO more obvious, and also why I decided against that; would it be a good idea to fix that as well?
for (; ; buffer += llen, size -= llen) {Carlo
[1] https://lore.kernel.org/git/YRGwjgAIyLPb7g50@coredump.intra.peff.net/