Modify

Ticket #3969 (closed Patches: fixed)

Opened 4 years ago

Last modified 4 years ago

position_to_offset() is broken for Microsoft Visual C++/Dinkumware

Reported by: gareth.sylvester-bradley@… Owned by: danieljames
Milestone: Boost 1.43.0 Component: iostreams
Version: Boost 1.42.0 Severity: Problem
Keywords: Cc:

Description

I have found a bug in position_to_offset() on Microsoft Visual C++/Dinkumware demonstrated by the following test app –

#include <iostream>
#include <boost/iostreams/positioning.hpp>

int main( int, char*[] )
{
  const boost::int64_t twoGB = 2 << 30;
  std::streampos pos = boost::iostreams::offset_to_position( twoGB );
  pos -= 2;
  if ( twoGB - 2 != boost::iostreams::position_to_offset( pos ) )
  {
    std::cout << "Failed!" << std::endl;
    return -1;
  }

  return 0;
}

This is resolved by the following patch to boost/iostreams/positioning.hpp.

105,106c105,106
<            static_cast<stream_offset>(static_cast<std::streamoff>(pos)) -
<            static_cast<stream_offset>(_FPOSOFF(streampos_to_fpos_t(pos)));
---
>            static_cast<stream_offset>(static_cast<std::streamoff>(pos) -
>                                       _FPOSOFF(streampos_to_fpos_t(pos)));

This has the potential to affect many parts of Boost.Iostreams but in particular it means the "small seeks optimization" in indirect_streambuf.hpp is broken.

Attachments

Change History

comment:1 Changed 4 years ago by danieljames

  • Owner changed from turkanis to danieljames
  • Status changed from new to assigned

comment:2 Changed 4 years ago by danieljames

(In [60581]) In position_to_offset, only cast to stream_offset after calculating _Myoff. Refs #3969.

Thanks to Garth Sylvester-Bradley.

comment:3 Changed 4 years ago by danieljames

  • Status changed from assigned to closed
  • Resolution set to fixed

(In [60666]) Merge iostreams.

  • Fix write_device_impl<ostream_tag>. Fixes #3839
  • Fix error checks after calling SetFilePointer?. Fixes #3953
  • Gzip filter shouldn't require its source to be peekable. Fixes #3723.
  • In position_to_offset, only cast to stream_offset after calculating _Myoff. Fixes #3969.
  • ptrdiff_t is in std. Fixes #2505.
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.