From 196de029044f4dbac5f74f68e08a89f778c3a236 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 23 Dec 2018 21:38:44 +0000 Subject: Be a bit more careful with fwrite. --- src/lib/config.cc | 6 +----- src/lib/internet.cc | 3 ++- src/lib/reel_writer.cc | 6 +++--- src/lib/util.cc | 17 +++++++++++++++++ src/lib/util.h | 1 + src/lib/writer.cc | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src/lib') diff --git a/src/lib/config.cc b/src/lib/config.cc index 172890dcf..eb2671365 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -987,11 +987,7 @@ Config::write_config () const if (!f) { throw FileError (_("Could not open file for writing"), cf); } - size_t const w = fwrite (s.c_str(), 1, s.length(), f); - if (w != s.length()) { - fclose (f); - throw FileError (_("Could not write whole file"), cf); - } + checked_fwrite (s.c_str(), s.length(), f, cf); fclose (f); } catch (xmlpp::exception& e) { string s = e.what (); diff --git a/src/lib/internet.cc b/src/lib/internet.cc index ad313bd3f..4eba1efa3 100644 --- a/src/lib/internet.cc +++ b/src/lib/internet.cc @@ -22,6 +22,7 @@ #include "compose.hpp" #include "exceptions.h" #include "cross.h" +#include "util.h" #include #include #include @@ -140,7 +141,7 @@ get_from_zip_url (string url, string file, bool pasv, function audio_channel_types (std::list mapped, int chann extern boost::shared_ptr remap (boost::shared_ptr input, int output_channels, AudioMapping map); extern Eyes increment_eyes (Eyes e); extern void checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path path); +extern void checked_fwrite (void const * ptr, size_t size, FILE* stream, boost::filesystem::path path); #endif diff --git a/src/lib/writer.cc b/src/lib/writer.cc index c31ae2a91..45a74624f 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -634,7 +634,7 @@ Writer::write_cover_sheet () boost::algorithm::replace_all (text, "$LENGTH", length); - fwrite (text.c_str(), 1, text.length(), f); + checked_fwrite (text.c_str(), text.length(), f, cover); fclose (f); } -- cgit v1.2.3