From 62448787ebfeba29c475b5713b97aaade1ce2243 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 19 Feb 2006 18:27:06 +0000 Subject: [PATCH] std_sstream.h (basic_stringbuf<>::setbuf): Simply clear the internal _M_string, adjust _M_sync call. 2006-02-19 Paolo Carlini * include/std/std_sstream.h (basic_stringbuf<>::setbuf): Simply clear the internal _M_string, adjust _M_sync call. * include/bits/sstream.tcc (basic_stringbuf<>::_M_sync): Adjust consistently for calls from setbuf. From-SVN: r111274 --- libstdc++-v3/ChangeLog | 7 +++++++ libstdc++-v3/include/bits/sstream.tcc | 28 +++++++++++++------------- libstdc++-v3/include/std/std_sstream.h | 4 ++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 99af0811454..1e1c79fb275 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2006-02-19 Paolo Carlini + + * include/std/std_sstream.h (basic_stringbuf<>::setbuf): Simply + clear the internal _M_string, adjust _M_sync call. + * include/bits/sstream.tcc (basic_stringbuf<>::_M_sync): Adjust + consistently for calls from setbuf. + 2006-02-17 Paolo Carlini Howard Hinnant diff --git a/libstdc++-v3/include/bits/sstream.tcc b/libstdc++-v3/include/bits/sstream.tcc index 95d3d4699be..2c5be334557 100644 --- a/libstdc++-v3/include/bits/sstream.tcc +++ b/libstdc++-v3/include/bits/sstream.tcc @@ -225,9 +225,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return __ret; } - // Assumes: contents of _M_string and internal buffer match exactly. - // __i == _M_in_cur - _M_in_beg - // __o == _M_out_cur - _M_out_beg template void basic_stringbuf<_CharT, _Traits, _Alloc>:: @@ -235,25 +232,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { const bool __testin = _M_mode & ios_base::in; const bool __testout = _M_mode & ios_base::out; - char_type* __end = __base + _M_string.size(); - + char_type* __endg = __base + _M_string.size(); + char_type* __endp = __base + _M_string.capacity(); + + if (__base != _M_string.data()) + { + // setbuf: __i == size of buffer area (_M_string.size() == 0). + __endg += __i; + __i = 0; + __endp = __endg; + } + if (__testin) - this->setg(__base, __base + __i, __end); + this->setg(__base, __base + __i, __endg); if (__testout) { - // If __base comes from setbuf we cannot trust capacity() - // to match the size of the buffer area: in general, after - // Step 1 in setbuf, _M_string.capacity() >= __n. - if (__base == _M_string.data()) - this->setp(__base, __base + _M_string.capacity()); - else - this->setp(__base, __end); + this->setp(__base, __endp); this->pbump(__o); // egptr() always tracks the string end. When !__testin, // for the correct functioning of the streambuf inlines // the other get area pointers are identical. if (!__testin) - this->setg(__end, __end, __end); + this->setg(__endg, __endg, __endg); } } diff --git a/libstdc++-v3/include/std/std_sstream.h b/libstdc++-v3/include/std/std_sstream.h index 712bf7ba3c7..f30c23bfeac 100644 --- a/libstdc++-v3/include/std/std_sstream.h +++ b/libstdc++-v3/include/std/std_sstream.h @@ -211,10 +211,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // things will quickly blow up. // Step 1: Destroy the current internal array. - _M_string.assign(__s, __n); + _M_string.clear(); // Step 2: Use the external array. - _M_sync(__s, 0, 0); + _M_sync(__s, __n, 0); } return this; }