stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Sebor (JIRA)" <j...@apache.org>
Subject [jira] Closed: (STDCXX-225) deriving from std::strstreambuf causes a coredump
Date Wed, 09 May 2007 04:17:15 GMT

     [ https://issues.apache.org/jira/browse/STDCXX-225?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Martin Sebor closed STDCXX-225.
-------------------------------

    Assignee: Martin Sebor

> deriving from std::strstreambuf causes a coredump
> -------------------------------------------------
>
>                 Key: STDCXX-225
>                 URL: https://issues.apache.org/jira/browse/STDCXX-225
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: 27. Input/Output
>         Environment: all
>            Reporter: Martin Sebor
>         Assigned To: Martin Sebor
>             Fix For: 4.2
>
>
> Moved from the Rogue Wave bug tracking database:
> ****Created By: sebor @ Sep 24, 2002 06:31:15 PM****
> -------- Original Message --------
> Subject: deriving from std::strstreambuf causes a coredump
> Date: Tue, 24 Sep 2002 13:07:48 -0700 (PDT)
> From: Mukesh Kapoor <Mukesh.Kapoor@Sun.COM>
> Reply-To: Mukesh Kapoor <Mukesh.Kapoor@Sun.COM>
> To: oemsupport@roguewave.com
> CC: Mukesh.Kapoor@Sun.COM
> Bug 4747931:
> -----------
> The following program dies with a coredump. The problem occurs with
> stdlib 2.2.3 also. It works fine with stlport. 
> Can you suggest a fix?
> #include <iostream>
> #include <strstream>
> #include <iomanip>
> #include <strings.h>
> using namespace std;
> class cLogStreamBuf : public strstreambuf
> // class cLogStreamBuf : public streambuf
> {
> private:
>   int               BufferSize;     // stream buffer size
>   char *            pBuffer;        // stream buffer
> protected:
>   virtual void Flush( bool fOverflow )
>   {
>     if (fOverflow)
>       *pptr() = '\0';
>     else
>     {
>       char *p = pptr() - 1;
>       *p = '\0';
>     }
>     cout << pBuffer << endl;
>     setp( pBuffer, pBuffer + BufferSize);
>   };
> public:
>   cLogStreamBuf( )
>       : strstreambuf ()
> //    : streambuf()
>   {
>     BufferSize = 16;
>     pBuffer = new char[ BufferSize + 1 ];     // allow for NULL
>     setp( pBuffer, pBuffer + BufferSize );    // init the put pointers
>   }
>   ~cLogStreamBuf()
>   {
>     delete [] pBuffer;
>   }
>   virtual int overflow( int ch )
>   {
>     cout << "overflow called" << endl;
>     Flush( true );
>     *pptr() = ch;
>     pbump (1);
>     return ch;
>   }
>   virtual int sync()
>   {
>     Flush (false);
>     return strstreambuf::sync();
> //    return streambuf::sync();
>   }
> };
> main()
> {
>   cLogStreamBuf * buf = new cLogStreamBuf();
>   ostream       out(buf);
>   const char *sp = "ABCD";
>   out << sp << endl;
>   const char *p = 
> "ABCDEFGHIJKLMNOPQRSTUVXYZ_ABCDEFGHIJKLMNOPQRSTUVXYZ_ABCDEFGHIJKLMNOPQRSTUVXYZ_A
> BCDEFGHIJKLMNOPQRSTUVXYZ_ABCDEFGHIJKLMNOPQRSTUVXYZ_ABCDEFGHIJKLMNOPQRSTUVXYZ";
>   char *p1 = NULL;
>   int   len = strlen(p);
>   for (int i = 140; i < len; i++)
>   {
>     p1 = new char[ i + 1 ];
>     strncpy(p1, p, i);
>     p1[i] = '\0';
>     cout <<  "i = " << i << endl;
>     out << p1 << endl;
>     delete p1;
>   }
>   return 0;
> }
> ****Modified By: sebor @ Sep 24, 2002 06:32:48 PM****
> -------- Original Message --------
> Subject: Re: deriving from std::strstreambuf causes a coredump
> Date: Tue, 24 Sep 2002 18:33:31 -0600
> From: Martin Sebor <sebor@roguewave.com>
> To: Mukesh Kapoor <Mukesh.Kapoor@Sun.COM>
> CC: oemsupport@roguewave.com
> References: <200209242007.NAA03114@phys-ha2mpka.Eng.Sun.COM>
> Mukesh Kapoor wrote:
> > Bug 4747931:
> > -----------
> > The following program dies with a coredump. The problem occurs with
> > stdlib 2.2.3 also. It works fine with stlport. 
> > Can you suggest a fix?
> It looks like strstreambuf::setbuf() makes the assumption that
> the buffer (called _C_buffer in our latest sources) is non-0
> and tries to memcpy() from it. The patch below fixed your test
> case for me. I have created PR #28340 to keep track of this
> since I'm too busy right now to carefully test it.
> Thanks
> Martin
> $ p4 diff -du //stdlib/dev/source/stdlib/strstream.cpp
> ==== //stdlib/dev/source/stdlib/strstream.cpp#18 - 
> /build/sebor/dev/stdlib/source/strstream.cpp ====
> @@ -298,9 +298,9 @@
>             if (pptr())
>             {
> -            __old_num_elements = pptr() - _C_buffer;
> +              __old_num_elements = _C_buffer ? pptr() - _C_buffer : 0;
> -            if ( __s!=_C_buffer )
> +            if (_C_buffer &&  __s != _C_buffer)
>                 memcpy(__s,_C_buffer,__old_num_elements);
>               setp (__s,__s+__n-1);
> ****Modified By: sebor @ Sep 25, 2002 11:46:59 AM****
> -------- Original Message --------
> Subject: Re: deriving from std::strstreambuf causes a coredump
> Date: Wed, 25 Sep 2002 10:39:35 -0700 (PDT)
> From: Mukesh Kapoor <Mukesh.Kapoor@Sun.COM>
> Reply-To: Mukesh Kapoor <Mukesh.Kapoor@Sun.COM>
> To: sebor@roguewave.com
> CC: oemsupport@roguewave.com
> Thanks. A similar change in our sources fixes the problem.
> Mukesh

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message