check for fflush() errors
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/got/got.c b/got/got.c
index ca784f2..1cd6152 100644
--- a/got/got.c
+++ b/got/got.c
@@ -690,7 +690,8 @@ print_commit(struct got_commit_object *commit, struct got_object_id *id,
printf("\n");
}
- fflush(stdout);
+ if (fflush(stdout) != 0 && err == NULL)
+ err = got_error_from_errno();
return err;
}
diff --git a/lib/diff3.c b/lib/diff3.c
index 9e996be..dcfc275 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -240,7 +240,10 @@ diffreg(BUF **d, const char *path1, const char *path2)
if (err)
goto done;
- fflush(outfile);
+ if (fflush(outfile) != 0) {
+ err = got_error_from_errno();
+ goto done;
+ }
*d = buf_load(outpath);
if (*d == NULL)
diff --git a/lib/object.c b/lib/object.c
index 7857608..4dd68b6 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1161,7 +1161,8 @@ got_object_blob_dump_to_file(size_t *total_len, int *nlines,
hdrlen = 0;
} while (len != 0);
- fflush(outfile);
+ if (fflush(outfile) != 0)
+ return got_error_from_errno();
rewind(outfile);
return NULL;
diff --git a/tog/tog.c b/tog/tog.c
index ba0eaeb..dd0a9ea 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1967,8 +1967,8 @@ create_diff(struct tog_diff_view_state *s)
break;
}
done:
- if (f)
- fflush(f);
+ if (f && fflush(f) != 0 && err == NULL)
+ err = got_error_from_errno();
return err;
}