Skip to content

Commit 34ad5a5

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

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
@@ -1117,8 +1117,16 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
11171117
emit_line(ecbdata->opt, plain, reset, line, len);
11181118
fputs("~\n", ecbdata->opt->file);
11191119
} else {
1120-
/* don't print the prefix character */
1121-
emit_line(ecbdata->opt, plain, reset, line+1, len-1);
1120+
/*
1121+
* Skip the prefix character, if any. With
1122+
* diff_suppress_blank_empty, there may be
1123+
* none.
1124+
*/
1125+
if (line[0] != '\n') {
1126+
line++;
1127+
len--;
1128+
}
1129+
emit_line(ecbdata->opt, plain, reset, line, len);
11221130
}
11231131
return;
11241132
}

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)