[Boost-bugs] [Boost C++ Libraries] #3447: After destruction binary_iarchive seeks to the end of file

Subject: [Boost-bugs] [Boost C++ Libraries] #3447: After destruction binary_iarchive seeks to the end of file
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-09-14 09:30:31


#3447: After destruction binary_iarchive seeks to the end of file
--------------------------------------------------------------------------------------------+
 Reporter: Andrey Upadyshev <oliora@…> | Owner: ramey
     Type: Bugs | Status: new
Milestone: | Component: serialization
  Version: Boost 1.39.0 | Severity: Problem
 Keywords: sync file stream basic_binary_iprimitive archive binary_iarchive serialization |
--------------------------------------------------------------------------------------------+
 After destruction binary_iarchive seeks to the end of file. This is
 occured because boost::archive::basic_binary_iprimitive (the ancestor of
 binary_iarchive) calls std::basic_streambuf::sync in destructor. Calling
 'sync' on a file streambuf seeks to the end of file.

 This is bad, because it lead to skipping of unread input data!

 I think calling 'sync' is a bad idea (and this call should be removed),
 but if it is necessary, then the documentation must clearly note that
 using a file streambuf with binary_iarchive skips to the end of the file.

 ----
 Example:

 {{{
 std::ifstream is( ARCHIVE_FILE_NAME, std::ios::binary );

 int i;

 {
     boost::archive::binary_iarchive ar( is, boost::archive::no_header );

     ar >> i;

     std::cout << "Pos after read: " << is.tellg() << std::endl;
 }

 std::cout << "Pos after dtor: " << is.tellg() << std::endl;
 }}}

 Output:
 {{{
 Pos after read: 4
 Pos after dtor: 11
 }}}
 (sizeof(int) is 4, archive file length is 11)

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3447>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:01 UTC