From: stsp Date: Tue, 13 Apr 2021 14:20:23 +0000 (+0000) Subject: Fix merging of files that lack a final \n at EOF after a block of common lines. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=08d4acf6df9a2cd5282efd339e89b74b913004ff;p=openbsd Fix merging of files that lack a final \n at EOF after a block of common lines. Problem reported by Josh Rickmar. ok millert@ --- diff --git a/usr.bin/cvs/diff3.c b/usr.bin/cvs/diff3.c index f0fee1c1925..70c625301b8 100644 --- a/usr.bin/cvs/diff3.c +++ b/usr.bin/cvs/diff3.c @@ -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++; diff --git a/usr.bin/diff3/diff3prog.c b/usr.bin/diff3/diff3prog.c index a56bfc7ce7a..f9f0004bab5 100644 --- a/usr.bin/diff3/diff3prog.c +++ b/usr.bin/diff3/diff3prog.c @@ -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++; diff --git a/usr.bin/rcs/diff3.c b/usr.bin/rcs/diff3.c index ebe04a3b705..98643c5d740 100644 --- a/usr.bin/rcs/diff3.c +++ b/usr.bin/rcs/diff3.c @@ -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++;