Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60581 - in trunk: boost/iostreams libs/iostreams/test
From: daniel_james_at_[hidden]
Date: 2010-03-14 14:00:46


Author: danieljames
Date: 2010-03-14 14:00:45 EDT (Sun, 14 Mar 2010)
New Revision: 60581
URL: http://svn.boost.org/trac/boost/changeset/60581

Log:
In `position_to_offset`, only cast to `stream_offset` after calculating `_Myoff`. Refs #3969.

Thanks to Garth Sylvester-Bradley.
Text files modified:
   trunk/boost/iostreams/positioning.hpp | 6 ++++--
   trunk/libs/iostreams/test/stream_offset_64bit_test.cpp | 17 ++++++++++++++++-
   2 files changed, 20 insertions(+), 3 deletions(-)

Modified: trunk/boost/iostreams/positioning.hpp
==============================================================================
--- trunk/boost/iostreams/positioning.hpp (original)
+++ trunk/boost/iostreams/positioning.hpp 2010-03-14 14:00:45 EDT (Sun, 14 Mar 2010)
@@ -102,8 +102,10 @@
 inline stream_offset position_to_offset(std::streampos pos)
 {
     return fpos_t_to_offset(streampos_to_fpos_t(pos)) +
- 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))
+ );
 }
 
 # endif // # ifndef BOOST_IOSTREAMS_HAS_DINKUMWARE_FPOS

Modified: trunk/libs/iostreams/test/stream_offset_64bit_test.cpp
==============================================================================
--- trunk/libs/iostreams/test/stream_offset_64bit_test.cpp (original)
+++ trunk/libs/iostreams/test/stream_offset_64bit_test.cpp 2010-03-14 14:00:45 EDT (Sun, 14 Mar 2010)
@@ -56,15 +56,30 @@
               << hex
               << static_cast<unsigned int>(off >> 32)
               << " and (off & 0xFFFFFFFF) == 0x"
- << static_cast<unsigned int>(off & 0xFFFFFFFF);
+ << static_cast<unsigned int>(off & 0xFFFFFFFF)
+ << std::endl;
             BOOST_REQUIRE_MESSAGE(0, s.str().c_str());
         }
     }
 }
 
+void stream_offset_64bit_test2()
+{
+ boost::int64_t val = boost::int64_t(1) << 31;
+ std::streampos pos = boost::iostreams::offset_to_position(val);
+ pos -= 2;
+ BOOST_CHECK_EQUAL(val - 2, boost::iostreams::position_to_offset(pos));
+
+ val = -val;
+ pos = boost::iostreams::offset_to_position(val);
+ pos += 2;
+ BOOST_CHECK_EQUAL(val + 2, boost::iostreams::position_to_offset(pos));
+}
+
 test_suite* init_unit_test_suite(int, char* [])
 {
     test_suite* test = BOOST_TEST_SUITE("stream_offset 64-bit test");
     test->add(BOOST_TEST_CASE(&stream_offset_64bit_test));
+ test->add(BOOST_TEST_CASE(&stream_offset_64bit_test2));
     return test;
 }


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