summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-05-23 10:27:42 -0700
committerJunio C Hamano <gitster@pobox.com>2011-05-23 10:27:42 -0700
commit34ad5a52b44d1b95f3b8833c02a0920f3454755b (patch)
tree633ed4e6b0d487b4b65202b9fcfbe6e4670b0785
parentc3c7797e1d151417333296ab3720614c1e235094 (diff)
parent42536dd9b9829b4eb4e3706e141b3c8bffa3e826 (diff)
downloadgit-34ad5a52b44d1b95f3b8833c02a0920f3454755b.tar.gz
Merge branch 'jm/maint-diff-words-with-sbe'
* jm/maint-diff-words-with-sbe: do not read beyond end of malloc'd buffer
-rw-r--r--diff.c12
-rwxr-xr-xt/t4034-diff-words.sh26
2 files changed, 36 insertions, 2 deletions
diff --git a/diff.c b/diff.c
index ba5f7aa217..8f4815bfd7 100644
--- a/diff.c
+++ b/diff.c
@@ -1117,8 +1117,16 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
emit_line(ecbdata->opt, plain, reset, line, len);
fputs("~\n", ecbdata->opt->file);
} else {
- /* don't print the prefix character */
- emit_line(ecbdata->opt, plain, reset, line+1, len-1);
+ /*
+ * Skip the prefix character, if any. With
+ * diff_suppress_blank_empty, there may be
+ * none.
+ */
+ if (line[0] != '\n') {
+ line++;
+ len--;
+ }
+ emit_line(ecbdata->opt, plain, reset, line, len);
}
return;
}
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 37aeab0d5c..c374aa4c1c 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -307,4 +307,30 @@ test_language_driver python
test_language_driver ruby
test_language_driver tex
+test_expect_success 'word-diff with diff.sbe' '
+ cat >expect <<-\EOF &&
+ diff --git a/pre b/post
+ index a1a53b5..bc8fe6d 100644
+ --- a/pre
+ +++ b/post
+ @@ -1,3 +1,3 @@
+ a
+
+ [-b-]{+c+}
+ EOF
+ cat >pre <<-\EOF &&
+ a
+
+ b
+ EOF
+ cat >post <<-\EOF &&
+ a
+
+ c
+ EOF
+ test_when_finished "git config --unset diff.suppress-blank-empty" &&
+ git config diff.suppress-blank-empty true &&
+ word_diff --word-diff=plain
+'
+
test_done