summaryrefslogtreecommitdiffstats
path: root/usr.bin/cvs/diff3.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/cvs/diff3.c')
-rw-r--r--usr.bin/cvs/diff3.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/usr.bin/cvs/diff3.c b/usr.bin/cvs/diff3.c
index e8e0512d85a..f0fee1c1925 100644
--- a/usr.bin/cvs/diff3.c
+++ b/usr.bin/cvs/diff3.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff3.c,v 1.63 2019/06/28 13:35:00 deraadt Exp $ */
+/* $OpenBSD: diff3.c,v 1.64 2020/06/26 07:28:47 stsp Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -798,9 +798,16 @@ edscript(int n)
diff_output("%da\n=======\n", de[n].old.to -1);
(void)fseek(fp[2], (long)de[n].new.from, SEEK_SET);
for (k = de[n].new.to-de[n].new.from; k > 0; k-= j) {
+ size_t r;
j = k > BUFSIZ ? BUFSIZ : k;
- if (fread(block, 1, j, fp[2]) != (size_t)j)
+ r = fread(block, 1, j, fp[2]);
+ if (r == 0) {
+ if (feof(fp[2]))
+ break;
return (-1);
+ }
+ if (r != (size_t)j)
+ j = r;
block[j] = '\0';
diff_output("%s", block);
}