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

Re: git show loop

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Mar 24, 2012, 15:18 UTC
Message-ID
<4F6DE5D6.4010408@lsrfire.ath.cx>
In-Reply-To
<4F6DC151.9040707@in.waw.pl>
Am 24.03.2012 13:42, schrieb Zbigniew Jędrzejewski-Szmek:
Show 11 quoted lines
> On 03/24/2012 12:50 PM, Zbigniew Jędrzejewski-Szmek wrote:
>> On 03/24/2012 11:05 AM, Julia Lawall wrote:
>>> In linux, git show 60d9aa7 -U0 goes into an infinite loop.
> 
> Bisect points to
> commit b810cbbde9232cbe9a3841edccc5b606bbd3a82e (refs/bisect/bad)
> Author: Junio C Hamano<gitster@pobox.com>
> Date:   Wed Jul 22 14:48:29 2009 -0700
> 
>       diff --cc: a lost line at the beginning of the file is shown
> incorrectly

That's what I found as well, but I don't understand how this relates to the patch below, which should fix the issue. Valgrind told me where to look instead.

-- >8 --
Subject: [PATCH] combine-diff: fix loop index underflow

If both la and context are zero at the start of the loop, la wraps around and we end up reading from memory far away. Skip the loop in that case instead.

Reported-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 combine-diff.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/combine-diff.c b/combine-diff.c
index a2e8dcf..9786680 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -423,7 +423,7 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
 						     hunk_begin, j);
 				la = (la + context < cnt + 1) ?
 					(la + context) : cnt + 1;
-				while (j <= --la) {
+				while (la && j <= --la) {
 					if (sline[la].flag & mark) {
 						contin = 1;
 						break;
-- 
1.7.9.2
Previous: Zbigniew Jędrzejewski-SzmekNext: Junio C Hamano
Message 4 of 5 in “git show loop”
  1. Julia LawallMar 24, 2012
  2. Zbigniew Jędrzejewski-SzmekMar 24, 2012
  3. Zbigniew Jędrzejewski-SzmekMar 24, 2012
  4. René ScharfeMar 24, 2012
  5. Junio C HamanoMar 26, 2012

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.