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/checksum.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bpkg/checksum.cxx') 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. -- cgit v1.1