Skip to content

Commit d9ac3e4

Browse files
committed
Merge branch 'jm/maint-diff-words-with-sbe' into maint
* jm/maint-diff-words-with-sbe: do not read beyond end of malloc'd buffer
2 parents 0531899 + 42536dd commit d9ac3e4

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

diff.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,16 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
10501050
emit_line(ecbdata->opt, plain, reset, line, len);
10511051
fputs("~\n", ecbdata->opt->file);
10521052
} else {
1053-
/* don't print the prefix character */
1054-
emit_line(ecbdata->opt, plain, reset, line+1, len-1);
1053+
/*
1054+
* Skip the prefix character, if any. With
1055+
* diff_suppress_blank_empty, there may be
1056+
* none.
1057+
*/
1058+
if (line[0] != '\n') {
1059+
line++;
1060+
len--;
1061+
}
1062+
emit_line(ecbdata->opt, plain, reset, line, len);
10551063
}
10561064
return;
10571065
}

t/t4034-diff-words.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,30 @@ test_language_driver python
307307
test_language_driver ruby
308308
test_language_driver tex
309309
310+
test_expect_success 'word-diff with diff.sbe' '
311+
cat >expect <<-\EOF &&
312+
diff --git a/pre b/post
313+
index a1a53b5..bc8fe6d 100644
314+
--- a/pre
315+
+++ b/post
316+
@@ -1,3 +1,3 @@
317+
a
318+
319+
[-b-]{+c+}
320+
EOF
321+
cat >pre <<-\EOF &&
322+
a
323+
324+
b
325+
EOF
326+
cat >post <<-\EOF &&
327+
a
328+
329+
c
330+
EOF
331+
test_when_finished "git config --unset diff.suppress-blank-empty" &&
332+
git config diff.suppress-blank-empty true &&
333+
word_diff --word-diff=plain
334+
'
335+
310336
test_done

0 commit comments

Comments
 (0)