combine-diff: fix loop index underflow
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Sat, 24 Mar 2012 15:18:46 +0000 (16:18 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Mar 2012 04:35:52 +0000 (21:35 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
combine-diff.c

index 9445e86c2f329858d5b805d144d6668526e0c289..45221f84a582640db7e784f19955bd58ba57ec48 100644 (file)
@@ -414,7 +414,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;