diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2020-11-18 17:38:43 +0100 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2021-03-01 12:57:00 +0100 |
commit | 545bc5f81d60fa6ff7c5cc43a2e9eef82f911466 (patch) | |
tree | a33547b406d578c4b4505dad2087e575d3fbab1f /src/util | |
parent | 8b6e4b3b23027da263d257b342f5d9a53e4032d5 (diff) |
util: fix WriteBinaryFile() claiming success even if error occurred
`fclose()` is flushing any buffered data to disk, so if it fails then
that could mean that the data was not completely written to disk.
Thus, check if `fclose()` succeeds and only then claim success from
`WriteBinaryFile()`.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/readwritefile.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/util/readwritefile.cpp b/src/util/readwritefile.cpp index 15e9d7a9b9..a45c41d367 100644 --- a/src/util/readwritefile.cpp +++ b/src/util/readwritefile.cpp @@ -40,6 +40,8 @@ bool WriteBinaryFile(const fs::path &filename, const std::string &data) fclose(f); return false; } - fclose(f); + if (fclose(f) != 0) { + return false; + } return true; } |