Commit cbe7f84890b5be0eb0e47f67f1606f66db181eae

Stefan Sperling 2019-02-11T11:35:55

check for fflush() errors

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;
 }