Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62957 - trunk/boost/iostreams/filter
From: steven_at_[hidden]
Date: 2010-06-14 19:36:44


Author: steven_watanabe
Date: 2010-06-14 19:36:43 EDT (Mon, 14 Jun 2010)
New Revision: 62957
URL: http://svn.boost.org/trac/boost/changeset/62957

Log:
Avoid calling BZ2_bzcompress after it has said that it's done. Fixes #2411. ([62952] is also necessary to make the test case from the ticket work.)
Text files modified:
   trunk/boost/iostreams/filter/bzip2.hpp | 14 +++++++++++---
   1 files changed, 11 insertions(+), 3 deletions(-)

Modified: trunk/boost/iostreams/filter/bzip2.hpp
==============================================================================
--- trunk/boost/iostreams/filter/bzip2.hpp (original)
+++ trunk/boost/iostreams/filter/bzip2.hpp 2010-06-14 19:36:43 EDT (Mon, 14 Jun 2010)
@@ -201,6 +201,7 @@
     void close();
 private:
     void init();
+ bool eof_; // Guard to make sure filter() isn't called after it returns false.
 };
 
 //
@@ -305,7 +306,7 @@
 
 template<typename Alloc>
 bzip2_compressor_impl<Alloc>::bzip2_compressor_impl(const bzip2_params& p)
- : bzip2_base(p) { }
+ : bzip2_base(p), eof_(false) { }
 
 template<typename Alloc>
 bool bzip2_compressor_impl<Alloc>::filter
@@ -313,17 +314,24 @@
       char*& dest_begin, char* dest_end, bool flush )
 {
     if (!ready()) init();
+ if (eof_) return false;
     before(src_begin, src_end, dest_begin, dest_end);
     int result = compress(flush ? bzip2::finish : bzip2::run);
     after(src_begin, dest_begin);
     bzip2_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(result);
- return result != bzip2::stream_end;
+ return !(eof_ = result == bzip2::stream_end);
 }
 
 template<typename Alloc>
 void bzip2_compressor_impl<Alloc>::close()
 {
- end(true);
+ try {
+ end(true);
+ } catch (...) {
+ eof_ = false;
+ throw;
+ }
+ eof_ = false;
 }
 
 template<typename Alloc>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk