diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-02 13:42:26 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-02 13:42:26 +0200 |
commit | 2a8177b5f51b6a930491bc50fb90d7eb9a8c6577 (patch) | |
tree | da946a7af108d5f4eb5c96d84a392b42a42c8fc6 /butl | |
parent | a22840fe77ef20f9c5488b9f2b8cf90663c537db (diff) |
Check for eof before streaming rdbuf
Diffstat (limited to 'butl')
-rw-r--r-- | butl/filesystem.cxx | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx index 4aa2078..3249b58 100644 --- a/butl/filesystem.cxx +++ b/butl/filesystem.cxx @@ -248,7 +248,11 @@ namespace butl // Throws ios::failure on fdbuf read/write failures. // - ofs << ifs.rdbuf (); + // Note that the eos check is important: if the stream is at eos (empty + // file) then this write will fail. + // + if (ifs.peek () != ifdstream::traits_type::eof ()) + ofs << ifs.rdbuf (); ifs.close (); // Throws ios::failure on failure. ofs.close (); // Throws ios::failure on flush/close failure. |