git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] for_each_reflog_ent_reverse: turn leftover check into assertion

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 5, 2014, 19:15 UTC
Message-ID
<xmqqsigtq56b.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20141205013244.GA16642@peff.net>
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.
Show 33 quoted lines
> -- >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);
Previous: Jeff KingNext: Junio C Hamano
Message 14 of 15 in “Bug in reflog of length 0x2BFF”
  1. Christoph MallonDec 1, 2014
  2. Christoph MallonDec 1, 2014
  3. Stefan BellerDec 1, 2014
  4. Christoph MallonDec 1, 2014
  5. Jonathan NiederDec 1, 2014
  6. Stefan BellerDec 2, 2014
  7. Christoph MallonDec 2, 2014
  8. Junio C HamanoDec 4, 2014
  9. Christoph MallonDec 4, 2014
  10. Jeff KingDec 4, 2014
  11. Junio C HamanoDec 4, 2014
  12. for_each_reflog_ent_reverse: fix newlines on block boundariesJeff King, Dec 5, 2014
  13. for_each_reflog_ent_reverse: turn leftover check into assertionJeff King, Dec 5, 2014
  14. Junio C HamanoDec 5, 2014
  15. Junio C HamanoDec 4, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.