public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Jeff King <peff@peff•net>
Cc: Christoph Mallon <mallon@cs•uni-saarland.de>,
	Jonathan Nieder <jrnieder@gmail•com>,
	git@vger•kernel.org, Stefan Beller <sbeller@google•com>
Subject: Re: [PATCH] for_each_reflog_ent_reverse: turn leftover check into assertion
Date: Fri, 05 Dec 2014 11:15:24 -0800	[thread overview]
Message-ID: <xmqqsigtq56b.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20141205013244.GA16642@peff.net> (Jeff King's message of "Thu, 4 Dec 2014 20:32:44 -0500")

Jeff King <peff@peff•net> writes:

> I _think_ the patch below is also applicable to the code before my
> boundary-fixing patch. But the rearranging also made me more confident
> in it.

Yeah, thanks for a fix.

> -- >8 --
> Subject: for_each_reflog_ent_reverse: turn leftover check into assertion
>
> Our loop should always process all lines, even if we hit the
> beginning of the file. We have a conditional after the loop
> ends to double-check that there is nothing left and to
> process it. But this should never happen, and is a sign of a
> logic bug in the loop. Let's turn it into a BUG assertion.
>
> Signed-off-by: Jeff King <peff@peff•net>
> ---
> Of course I cannot say something like "this can never happen; the old
> code was wrong to handle this case" without a nagging feeling that I am
> missing something, so extra careful eyes are appreciated (and are why I
> would rather have an assert here than removing the code and silently
> dropping lines if I am wrong).
>
>  refs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/refs.c b/refs.c
> index ccb8834..1f77fa6 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -3451,7 +3451,7 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void
>  
>  	}
>  	if (!ret && sb.len)
> -		ret = show_one_reflog_ent(&sb, fn, cb_data);
> +		die("BUG: reverse reflog parser had leftover data");
>  
>  	fclose(logfp);
>  	strbuf_release(&sb);

  reply	other threads:[~2014-12-05 19:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-01 15:15 Bug in reflog of length 0x2BFF Christoph Mallon
2014-12-01 16:00 ` Christoph Mallon
2014-12-01 18:53   ` Stefan Beller
2014-12-01 22:30     ` Christoph Mallon
2014-12-01 23:35 ` Jonathan Nieder
2014-12-02  1:39   ` Stefan Beller
2014-12-02  6:13   ` Christoph Mallon
2014-12-04 20:18   ` Junio C Hamano
2014-12-04 20:37     ` Christoph Mallon
2014-12-04 21:58       ` Jeff King
2014-12-04 22:14         ` Junio C Hamano
2014-12-05  1:28           ` [PATCH] for_each_reflog_ent_reverse: fix newlines on block boundaries Jeff King
2014-12-05  1:32             ` [PATCH] for_each_reflog_ent_reverse: turn leftover check into assertion Jeff King
2014-12-05 19:15               ` Junio C Hamano [this message]
2014-12-04 22:10       ` Bug in reflog of length 0x2BFF 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=xmqqsigtq56b.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=jrnieder@gmail$(echo .)com \
    --cc=mallon@cs$(echo .)uni-saarland.de \
    --cc=peff@peff$(echo .)net \
    --cc=sbeller@google$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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