summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent R. Spillner <kspillner@cvs.openbsd.org>2014-08-27 15:22:41 +0000
committerKent R. Spillner <kspillner@cvs.openbsd.org>2014-08-27 15:22:41 +0000
commitb9ff7b734761c97992146bee51935bb71ebc46d7 (patch)
treef427d0be1ad68146548c01648a2734bbd8fc3289
parent99d89c1690382ed26c445bedf4733dc2ee80f34d (diff)
Ensure diff -uw always produces valid output when one file doesn't end
with a newline. Issue reported by guenther@. ok guenther@
-rw-r--r--usr.bin/diff/diffreg.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 14f0d17bf32..f949cd27c27 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.82 2012/07/08 15:48:56 stsp Exp $ */
+/* $OpenBSD: diffreg.c,v 1.83 2014/08/27 15:22:40 kspillner Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -778,10 +778,14 @@ check(FILE *f1, FILE *f2, int flags)
* GNU diff ignores a missing newline
* in one file for -b or -w.
*/
- if ((flags & (D_FOLDBLANKS|D_IGNOREBLANKS)) &&
- ((c == EOF && d == '\n') ||
- (c == '\n' && d == EOF))) {
- break;
+ if (flags & (D_FOLDBLANKS|D_IGNOREBLANKS)) {
+ if (c == EOF && d == '\n') {
+ ctnew++;
+ break;
+ } else if (c == '\n' && d == EOF) {
+ ctold++;
+ break;
+ }
}
ctold++;
ctnew++;