aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-02 13:56:20 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-02 13:56:20 +0200
commite59571ffcdcd942874f3fa8199c880b114d874f9 (patch)
treeeb39ea19f5872e4de08ce514d6e53d588f608d2d
parentb94b5381f68061121c22f2786ba1fa774f1ee6f6 (diff)
Check for eof before streaming rdbuf
-rw-r--r--bpkg/checksum.cxx7
-rw-r--r--bpkg/fetch.cxx9
2 files changed, 13 insertions, 3 deletions
diff --git a/bpkg/checksum.cxx b/bpkg/checksum.cxx
index 023e641..3f52204 100644
--- a/bpkg/checksum.cxx
+++ b/bpkg/checksum.cxx
@@ -330,7 +330,12 @@ namespace bpkg
ifdstream is (pr.in_ofd, fdstream_mode::skip);
ofdstream os (pr.out_fd);
- os << &sb;
+ // Note that the eof check is important: if the stream is at eof, write
+ // will fail.
+ //
+ if (sb.sgetc () != ifdstream::traits_type::eof ())
+ os << &sb;
+
os.close ();
// All three tools output the sum as the first word.
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));