summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2007-12-16 02:06:14 -0500
committerJunio C Hamano <gitster@pobox.com>2007-12-16 11:53:03 -0800
commit52499977350b95ba7166e5c835b09cdbc20a3d02 (patch)
tree02a7e07c39cbe6987f213cda07d2067e1df97997
parent7680087e7c8125e7397aa5761f5c5ddbb02a8326 (diff)
downloadgit-52499977350b95ba7166e5c835b09cdbc20a3d02.tar.gz
trim_common_tail: brown paper bag fix.
The recovered context lines were not LF terminated due to off-by-one error, which also caused the outer loop to count the number of recovered lines to terminate after running only once. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--xdiff-interface.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 700def211e..98b02eda35 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -110,7 +110,7 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx)
{
const int blk = 1024;
- long trimmed = 0, recovered = 0, i;
+ long trimmed = 0, recovered = 0;
char *ap = a->ptr + a->size;
char *bp = b->ptr + b->size;
long smaller = (a->size < b->size) ? a->size : b->size;
@@ -121,10 +121,9 @@ static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx)
bp -= blk;
}
- for (i = 0, recovered = 0; recovered < trimmed && i <= ctx; i++) {
- while (recovered < trimmed && ap[recovered] != '\n')
- recovered++;
- }
+ while (recovered < trimmed && ctx)
+ if (ap[recovered++] == '\n')
+ ctx--;
a->size -= (trimmed - recovered);
b->size -= (trimmed - recovered);
}