Opened 9 years ago

#8572 new Bugs

iosteams indirect_streambuf::init_put_area should seek if data has been read from the get buffer

Reported by: Alan Birtles <alan.birtles@…> Owned by: Jonathan Turkanis
Milestone: To Be Determined Component: iostreams
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

The following code with std::fstream prints 0x1801 but with boost::iostream prints 0x2000:

  boost::iostreams::stream< boost::iostreams::file > ios( boost::iostreams::file( "test.dat", std::ios_base::binary | std::ios_base::in | std::ios_base::out | std::ios_base::trunc ), 0x800 );
  //std::fstream ios( "test.dat", std::ios_base::binary | std::ios_base::in | std::ios_base::out | std::ios_base::trunc );
  char buffer[ 0x2000 ];
  ios.write( buffer, 0x2000 );
  ios.seekg( -0x1000, std::ios_base::cur );
  ios.get();
  ios.write( buffer, 0x800 );
  std::cout << std::hex << ios.tellp() << std::endl;
  std::cout << std::hex << ios.tellg() << std::endl;

I believe the problem lies in indirect_streambuf::init_put_area. The current implementation is:

    if (shared_buffer() && gptr() != 0)
        setg(0, 0, 0);
    if (output_buffered())
        setp(out().begin(), out().end());
    else
        setp(0, 0);

I think it should be:

    if (shared_buffer() && gptr() != 0)
    {
        obj().seek(gptr()-egptr(), BOOST_IOS::cur, BOOST_IOS::in, next_);
        setg(0, 0, 0);
    }
    if (output_buffered())
        setp(out().begin(), out().end());
    else
        setp(0, 0);

Change History (0)

Note: See TracTickets for help on using tickets.