diff --git a/src/util.c b/src/util.c index 016057d..44ce61f 100644 --- a/src/util.c +++ b/src/util.c @@ -817,7 +817,8 @@ analyze_hunk (struct change *hunk, for (i = next->line0; i <= l0 && trivial; i++) { char const *line = linbuf0[i]; - char const *newline = linbuf0[i + 1] - 1; + char const *lastbyte = linbuf0[i + 1] - 1; + char const *newline = lastbyte + (*lastbyte != '\n'); size_t len = newline - line; char const *p = line; if (skip_white_space) @@ -837,7 +838,8 @@ analyze_hunk (struct change *hunk, for (i = next->line1; i <= l1 && trivial; i++) { char const *line = linbuf1[i]; - char const *newline = linbuf1[i + 1] - 1; + char const *lastbyte = linbuf1[i + 1] - 1; + char const *newline = lastbyte + (*lastbyte != '\n'); size_t len = newline - line; char const *p = line; if (skip_white_space) diff --git a/tests/no-newline-at-eof b/tests/no-newline-at-eof index 14d5f49..f503718 100755 --- a/tests/no-newline-at-eof +++ b/tests/no-newline-at-eof @@ -50,4 +50,10 @@ compare exp2 out || fail=1 # expect empty stderr compare /dev/null err || fail=1 +# Test for Bug#18402. +printf a > a +printf b > b +diff -B a b > out 2>err +test $? = 1 || fail=1 + Exit $fail