This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] _M_out_lim vs setp
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: bkoz <bkoz at redhat dot com>
- Date: Wed, 16 Apr 2003 23:25:00 +0200
- Subject: [Patch] _M_out_lim vs setp
Hi all, hi Benjamin,
I'm currently working on removing some unnecessary checks
for NULL pointers and noticed this bit which seems not ok
from a correctness point of view.
Basing on the semantics of _M_out_lim seems obvious that,
upon setp() it should be equal to _M_out_beg. Then at each
put operation it will move forward, toward _M_out_end.
Consider, for instance, the effect of the _M_really_overflow
call present in close(): if we didn't do any put operation
we are not supposed to write out anything. However, since the
former flushes all the chars between _M_out_beg and _M_out_lim,
for a setp put area we end up writing garbage.
Thus the patch below, tested x86-linux. Ok?
Paolo.
/////////
2003-04-16 Paolo Carlini <pcarlini at unitus dot it>
* include/std/std_streambuf.h (setp): _M_out_lim, being
the end limit of used put area, is set equal to _M_out_beg.
*** std_streambuf.h.~1.18.~ Tue Apr 15 00:43:32 2003
--- std_streambuf.h Wed Apr 16 22:18:47 2003
*************** namespace std
*** 629,636 ****
void
setp(char_type* __pbeg, char_type* __pend)
{
! _M_out_beg = _M_out_cur = __pbeg;
! _M_out_end = _M_out_lim = __pend;
if (!(_M_mode & ios_base::out) && __pbeg && __pend)
_M_mode = _M_mode | ios_base::out;
}
--- 629,636 ----
void
setp(char_type* __pbeg, char_type* __pend)
{
! _M_out_beg = _M_out_cur = _M_out_lim = __pbeg;
! _M_out_end = __pend;
if (!(_M_mode & ios_base::out) && __pbeg && __pend)
_M_mode = _M_mode | ios_base::out;
}