This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Fix seek to beg after grow bug
- From: Nathan Myers <ncm-nospam at cantrip dot org>
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 18 Feb 2003 13:15:12 -0800
- Subject: Re: [Patch] Fix seek to beg after grow bug
- References: <3E529279.9070206@unitus.it>
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
ncm-nospam@cantrip.org