From 2a8177b5f51b6a930491bc50fb90d7eb9a8c6577 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 2 Aug 2016 13:42:26 +0200 Subject: Check for eof before streaming rdbuf --- butl/filesystem.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'butl') 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. -- cgit v1.1