You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Farid Zaripov <Fa...@epam.com> on 2007/08/09 19:27:06 UTC

[PATCH] STDCXX-515

  Below is the patch for fix STDCXX-515.

  ChangeLog:
  * sstream.cc (xsputn): Correct write position after growing the
buffer.

Index: sstream.cc
===================================================================
--- sstream.cc	(revision 564229)
+++ sstream.cc	(working copy)
@@ -185,10 +185,16 @@
         const _RWSTD_SIZE_T __bufsize =
             __n + (this->pptr () - this->pbase ());
 
+        // preserve current pptr() since str() would seek to end
+        const streamsize __cur = this->pptr () - this->pbase ();
+
         // grow the buffer if necessary to accommodate the whole
         // string plus the contents of the buffer up to pptr()
         str (this->_C_buffer, __bufsize);
 
+        // restore pptr()
+        this->pbump (__cur - (this->pptr () - this->pbase ()));
+
         _RWSTD_ASSERT (__n <= this->epptr () - this->pptr ());
     }
 

Farid.

RE: [PATCH] STDCXX-515

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:sebor@roguewave.com] 
> Sent: Tuesday, August 14, 2007 6:47 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: [PATCH] STDCXX-515
> 
> Farid Zaripov wrote:
> >   Below is the patch for fix STDCXX-515.
> > 
> >   ChangeLog:
> >   * sstream.cc (xsputn): Correct write position after growing the 
> > buffer.
> 
> Why do we need to do it in xsputn()? Isn't str() supposed to keep
> pptr() at the right offset after growing the buffer?

  No.

-----------------
27.7.1.2 Member functions [stringbuf.members]

void str(const basic_string<charT,traits,Allocator>& s );

2 Effects: Copies the content of s into the basic_stringbuf underlying
character sequence. If mode & ios_-
base::out is true, initializes the output sequence such that pbase()
points to the first underlying character,
epptr() points one past the last underlying character, and pptr() is
equal to epptr() if mode &ios_base::in
is true, otherwise pptr() is equal to pbase().
-----------------

Farid.

Re: [PATCH] STDCXX-515

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>   Below is the patch for fix STDCXX-515.
> 
>   ChangeLog:
>   * sstream.cc (xsputn): Correct write position after growing the
> buffer.

Why do we need to do it in xsputn()? Isn't str() supposed to keep
pptr() at the right offset after growing the buffer?

Martin

> 
> Index: sstream.cc
> ===================================================================
> --- sstream.cc	(revision 564229)
> +++ sstream.cc	(working copy)
> @@ -185,10 +185,16 @@
>          const _RWSTD_SIZE_T __bufsize =
>              __n + (this->pptr () - this->pbase ());
>  
> +        // preserve current pptr() since str() would seek to end
> +        const streamsize __cur = this->pptr () - this->pbase ();
> +
>          // grow the buffer if necessary to accommodate the whole
>          // string plus the contents of the buffer up to pptr()
>          str (this->_C_buffer, __bufsize);
>  
> +        // restore pptr()
> +        this->pbump (__cur - (this->pptr () - this->pbase ()));
> +
>          _RWSTD_ASSERT (__n <= this->epptr () - this->pptr ());
>      }
>  
> 
> Farid.