Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58225 - trunk/boost/iostreams/detail
From: daniel_james_at_[hidden]
Date: 2009-12-07 14:36:40


Author: danieljames
Date: 2009-12-07 14:36:38 EST (Mon, 07 Dec 2009)
New Revision: 58225
URL: http://svn.boost.org/trac/boost/changeset/58225

Log:
If a write is going to go past the end of the restricted area, write up to the end before throwing an exception.
Text files modified:
   trunk/boost/iostreams/detail/restrict_impl.hpp | 11 +++++++++--
   1 files changed, 9 insertions(+), 2 deletions(-)

Modified: trunk/boost/iostreams/detail/restrict_impl.hpp
==============================================================================
--- trunk/boost/iostreams/detail/restrict_impl.hpp (original)
+++ trunk/boost/iostreams/detail/restrict_impl.hpp 2009-12-07 14:36:38 EST (Mon, 07 Dec 2009)
@@ -160,8 +160,12 @@
     {
         if (!open_)
             open(snk, BOOST_IOS::out);
- if (end_ != -1 && pos_ + n >= end_)
+ if (end_ != -1 && pos_ + n >= end_) {
+ if(pos_ < end_)
+ pos_ += iostreams::write(this->component(),
+ snk, s, end_ - pos_);
             boost::throw_exception(bad_write());
+ }
         std::streamsize result =
             iostreams::write(this->component(), snk, s, n);
         pos_ += result;
@@ -272,8 +276,11 @@
 inline std::streamsize restricted_indirect_device<Device>::write
     (const char_type* s, std::streamsize n)
 {
- if (end_ != -1 && pos_ + n >= end_)
+ if (end_ != -1 && pos_ + n >= end_) {
+ if(pos_ < end_)
+ pos_ += iostreams::write(this->component(), s, end_ - pos_);
         boost::throw_exception(bad_write());
+ }
     std::streamsize result = iostreams::write(this->component(), s, n);
     pos_ += result;
     return result;


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