@matheusbsbs / matheus-bagliano / commits / 5249997735
Fork 0

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>

Jeff King committed Dec 16, 2007 at 02:06 UTC 52499977350b95ba7166e5c835b09cdbc20a3d02
1 file changed +4 -5
xdiff-interface.c
+4 -5
@@ -110,7 +110,7 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
110 static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx)
111 {
112 const int blk = 1024;
113 - long trimmed = 0, recovered = 0, i;
113 + long trimmed = 0, recovered = 0;
114 char *ap = a->ptr + a->size;
115 char *bp = b->ptr + b->size;
116 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)
121 bp -= blk;
122 }
123
124 - for (i = 0, recovered = 0; recovered < trimmed && i <= ctx; i++) {
125 - while (recovered < trimmed && ap[recovered] != '\n')
126 - recovered++;
127 - }
124 + while (recovered < trimmed && ctx)
125 + if (ap[recovered++] == '\n')
126 + ctx--;
127 a->size -= (trimmed - recovered);
128 b->size -= (trimmed - recovered);
129 }