fix merging with files that do not contain a newline character; ok millert@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/lib/diff3.c b/lib/diff3.c
index f17c676..e8841fa 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -1002,10 +1002,17 @@ edscript(int n, struct diff3_state *d3s)
return got_error_from_errno("fseeko");
k = (size_t)(d3s->de[n].oldo.to - d3s->de[n].oldo.from);
for (; k > 0; k -= len) {
+ size_t r;
len = k > BUFSIZ ? BUFSIZ : k;
- if (fread(block, 1, len, d3s->fp[1]) != len)
+ r = fread(block, 1, len, d3s->fp[1]);
+ if (r == 0) {
+ if (feof(d3s->fp[1]))
+ break;
return got_ferror(d3s->fp[1],
GOT_ERR_IO);
+ }
+ if (r != len)
+ len = r;
block[len] = '\0';
err = diff_output(d3s->diffbuf, "%s", block);
if (err)
@@ -1026,9 +1033,17 @@ edscript(int n, struct diff3_state *d3s)
return got_error_from_errno("fseek");
k = (size_t)(d3s->de[n].newo.to - d3s->de[n].newo.from);
for (; k > 0; k -= len) {
+ size_t r;
len = k > BUFSIZ ? BUFSIZ : k;
- if (fread(block, 1, len, d3s->fp[2]) != len)
- return got_ferror(d3s->fp[2], GOT_ERR_IO);
+ r = fread(block, 1, len, d3s->fp[2]);
+ if (r == 0) {
+ if (feof(d3s->fp[2]))
+ break;
+ return got_ferror(d3s->fp[2],
+ GOT_ERR_IO);
+ }
+ if (r != len)
+ len = r;
block[len] = '\0';
err = diff_output(d3s->diffbuf, "%s", block);
if (err)