From e59571ffcdcd942874f3fa8199c880b114d874f9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 2 Aug 2016 13:56:20 +0200 Subject: Check for eof before streaming rdbuf --- bpkg/fetch.cxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'bpkg/fetch.cxx') diff --git a/bpkg/fetch.cxx b/bpkg/fetch.cxx index 85d6583..1c9b623 100644 --- a/bpkg/fetch.cxx +++ b/bpkg/fetch.cxx @@ -578,9 +578,14 @@ namespace bpkg // the manifest parsing. // ifdstream is (pr.in_ofd, fdstream_mode::binary); - stringstream bs (ios::in | ios::out | ios::binary); - bs << is.rdbuf (); + + // Note that the eof check is important: if the stream is at eof, write + // will fail. + // + if (is.peek () != ifdstream::traits_type::eof ()) + bs << is.rdbuf (); + is.close (); string sha256sum (sha256 (o, bs)); -- cgit v1.1