This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Fix seek to beg after grow bug

On Tue, Feb 18, 2003 at 09:07:21PM +0100, Paolo Carlini wrote:
> the below is the fix for the problem noticed by Peter Hrenka today.
> We had this code in str():
>        __size_type __len = _M_string.size();
>        if (this->_M_out_cur > this->_M_out_beg)
>          __len = std::max(__size_type(this->_M_out_end
>                           - this->_M_out_beg), __len);
> which failed to compute the correct __len when _M_out_cur was
> equal to _M_out_beg upon a seek to ios_base::beg.
> We must check instead that _M_out_end > _M_out_beg, since
> _M_out_end >= _M_out_cur and stores the current string end.
> Tested x86-linux. I'd like to apply it to mainline, and, after a
> little while of additional testing, 3_3 too.

This doesn't seem quite right.  I think the right code is
more like just

      __size_type __len = std::max(_M_string.size(),
        __size_type(this->_M_out_cur - this->_M_out_beg));

In other words, either cur and beg are both 0, or (cur - beg) is 
at least as large as the string.  

We have to be sure, too, that in seek{pos,off}, the string length gets 
updated like the above before _M_out_cur gets moved, because sometimes 
_M_out_cur is our only record of how long the string really has become.  
Likewise, whenever the buffer gets lengthened, the string capacity 
needs to be updated along with _M_out_end.

Or maybe I'm hallucinating from lack of sleep.

Nathan Myers

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]