aboutsummaryrefslogtreecommitdiff
path: root/butl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-02 13:42:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-02 13:42:26 +0200
commit2a8177b5f51b6a930491bc50fb90d7eb9a8c6577 (patch)
treeda946a7af108d5f4eb5c96d84a392b42a42c8fc6 /butl
parenta22840fe77ef20f9c5488b9f2b8cf90663c537db (diff)
Check for eof before streaming rdbuf
Diffstat (limited to 'butl')
-rw-r--r--butl/filesystem.cxx6
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.