summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS7
-rw-r--r--src/io.c11
2 files changed, 17 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 2d20b40..88af7ef 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU diffutils NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ diff once again prints the required "\ No newline at end of file" line
+ when at least one input lacks a newline-at-EOF and the final hunk plus
+ context-length aligns exactly with the end of the newline-lacking file.
+ [bug introduced between 2.8.7 and 2.9]
+
** Changes in behavior
In context-style diffs, diff prints a portion of a preceding "function"
diff --git a/src/io.c b/src/io.c
index aeeb51d..11f9ee3 100644
--- a/src/io.c
+++ b/src/io.c
@@ -220,6 +220,7 @@ find_and_hash_each_line (struct file_data *current)
bool same_length_diff_contents_compare_anyway =
diff_length_compare_anyway | ignore_case;
+ bool missing_newline_fixup = false;
while (p < suffix_begin)
{
char const *ip = p;
@@ -376,6 +377,7 @@ find_and_hash_each_line (struct file_data *current)
&& current->missing_newline
&& ROBUST_OUTPUT_STYLE (output_style))
{
+ missing_newline_fixup = true;
/* This line is incomplete. If this is significant,
put the line into buckets[-1]. */
if (ignore_white_space < IGNORE_SPACE_CHANGE)
@@ -471,7 +473,14 @@ find_and_hash_each_line (struct file_data *current)
linbuf[line] = p;
if (p == bufend)
- break;
+ {
+ /* If we've added a newline sentinel and did not adjust "bufend"
+ above, then linbuf[line] is now pointing at the sentinel, yet
+ should instead be pointing to the preceding byte. */
+ if (!missing_newline_fixup && current->missing_newline)
+ --linbuf[line];
+ break;
+ }
if (context <= i && no_diff_means_no_output)
break;