Re: trim_common_tail bug?
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 16, 2007, 19:43 UTC
- Message-ID
- <7v8x3ul927.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <20071216070614.GA5072@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 17 quoted lines
> On Sat, Dec 15, 2007 at 03:02:02PM -0500, Jeff King wrote:
>
>> > for (i = 0, recovered = 0; recovered < trimmed && i <= ctx; i++) {
>> > while (recovered < trimmed && ap[recovered++] != '\n')
>> > ; /* nothing */
>> > }
>> >
>> > then (warning: I haven't had my coffee yet)?
>>
>> Yes, I think that is equivalent. My sleep-deprived brain keeps thinking
>> there must be a more clear way of writing this whole loop, but it
>> escapes me at the moment.
>
> And this came to me in a dream. :) It fixes the bug, and I think it is a
> bit simpler to see the termination conditions in a single loop. But
> please double-check correctness, and that you agree that it is more
> readable.I wanted to recover to the end of the line that includes the cut-off point, even when (ctx == 0), to be extra safer, but I do not think it was necessary.
Show 10 quoted lines
> ... > bp -= blk; > } > > + while (recovered < trimmed && ctx) > + if (ap[recovered++] == '\n') > + ctx--; > a->size -= (trimmed - recovered); > b->size -= (trimmed - recovered); > }