Fix merging of files that lack a final \n at EOF after a block of common lines.
authorstsp <stsp@openbsd.org>
Tue, 13 Apr 2021 14:20:23 +0000 (14:20 +0000)
committerstsp <stsp@openbsd.org>
Tue, 13 Apr 2021 14:20:23 +0000 (14:20 +0000)
Problem reported by Josh Rickmar.
ok millert@

usr.bin/cvs/diff3.c
usr.bin/diff3/diff3prog.c
usr.bin/rcs/diff3.c

index f0fee1c..70c6253 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: diff3.c,v 1.64 2020/06/26 07:28:47 stsp Exp $ */
+/*     $OpenBSD: diff3.c,v 1.65 2021/04/13 14:20:23 stsp Exp $ */
 
 /*
  * Copyright (C) Caldera International Inc.  2001-2002.
@@ -743,6 +743,8 @@ duplicate(struct range *r1, struct range *r2)
                do {
                        c = getc(fp[0]);
                        d = getc(fp[1]);
+                       if (c == -1 && d == -1)
+                               break;
                        if (c == -1 || d== -1)
                                return (-1);
                        nchar++;
index a56bfc7..f9f0004 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: diff3prog.c,v 1.20 2020/06/26 07:28:47 stsp Exp $     */
+/*     $OpenBSD: diff3prog.c,v 1.21 2021/04/13 14:20:23 stsp Exp $     */
 
 /*
  * Copyright (C) Caldera International Inc.  2001-2002.
@@ -494,6 +494,8 @@ duplicate(struct range *r1, struct range *r2)
                do {
                        c = getc(fp[0]);
                        d = getc(fp[1]);
+                       if (c == -1 && d == -1)
+                               break;
                        if (c == -1 || d== -1)
                                trouble();
                        nchar++;
index ebe04a3..98643c5 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: diff3.c,v 1.44 2020/06/26 07:28:46 stsp Exp $ */
+/*     $OpenBSD: diff3.c,v 1.45 2021/04/13 14:20:24 stsp Exp $ */
 
 /*
  * Copyright (C) Caldera International Inc.  2001-2002.
@@ -838,6 +838,8 @@ duplicate(struct range *r1, struct range *r2)
                do {
                        c = getc(fp[0]);
                        d = getc(fp[1]);
+                       if (c == -1 && d == -1)
+                               break;
                        if (c == -1 || d== -1)
                                return (-1);
                        nchar++;