From: Carl Hetherington Date: Sun, 23 Dec 2018 21:38:44 +0000 (+0000) Subject: Be a bit more careful with fwrite. X-Git-Tag: v2.13.91~10 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=196de029044f4dbac5f74f68e08a89f778c3a236 Be a bit more careful with fwrite. --- 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); } diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index ccf1202ec..8b6d215a2 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -536,7 +536,7 @@ CertificateChainEditor::export_certificate () } string const s = j->certificate (true); - fwrite (s.c_str(), 1, s.length(), f); + checked_fwrite (s.c_str(), s.length(), f, path); fclose (f); } d->Destroy (); @@ -709,7 +709,7 @@ CertificateChainEditor::export_private_key () } string const s = _get()->key().get (); - fwrite (s.c_str(), 1, s.length(), f); + checked_fwrite (s.c_str(), s.length(), f, path); fclose (f); } d->Destroy (); @@ -805,10 +805,10 @@ KeysPage::export_decryption_chain_and_key () } string const chain = Config::instance()->decryption_chain()->chain(); - fwrite (chain.c_str(), 1, chain.length(), f); + checked_fwrite (chain.c_str(), chain.length(), f, path); optional const key = Config::instance()->decryption_chain()->key(); DCPOMATIC_ASSERT (key); - fwrite (key->c_str(), 1, key->length(), f); + checked_fwrite (key->c_str(), key->length(), f, path); fclose (f); } d->Destroy (); @@ -883,7 +883,7 @@ KeysPage::export_decryption_chain () } string const s = Config::instance()->decryption_chain()->chain(); - fwrite (s.c_str(), 1, s.length(), f); + checked_fwrite (s.c_str(), s.length(), f, path); fclose (f); } d->Destroy (); @@ -905,7 +905,7 @@ KeysPage::export_decryption_certificate () } string const s = Config::instance()->decryption_chain()->leaf().certificate (true); - fwrite (s.c_str(), 1, s.length(), f); + checked_fwrite (s.c_str(), s.length(), f, path); fclose (f); } diff --git a/src/wx/swaroop_controls.cc b/src/wx/swaroop_controls.cc index 36aac7cff..d6ab5c39d 100644 --- a/src/wx/swaroop_controls.cc +++ b/src/wx/swaroop_controls.cc @@ -158,7 +158,7 @@ SwaroopControls::viewer_position_changed () + " " + dcp::raw_convert(_selected_playlist_position) + " " + dcp::raw_convert(_viewer->position().get()); - fwrite (p.c_str(), p.length(), 1, f); + checked_fwrite (p.c_str(), p.length(), f, Config::path("position")); fclose (f); } }