Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 73159 invoked from network); 28 Jun 2006 18:27:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Jun 2006 18:27:09 -0000 Received: (qmail 81739 invoked by uid 500); 28 Jun 2006 18:27:09 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 81634 invoked by uid 500); 28 Jun 2006 18:27:08 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 81575 invoked by uid 99); 28 Jun 2006 18:27:08 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Jun 2006 11:27:08 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [209.237.227.198] (HELO brutus.apache.org) (209.237.227.198) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Jun 2006 11:27:05 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id D54A5410005 for ; Wed, 28 Jun 2006 18:25:29 +0000 (GMT) Message-ID: <10486821.1151519129870.JavaMail.jira@brutus> Date: Wed, 28 Jun 2006 18:25:29 +0000 (GMT+00:00) From: "Martin Sebor (JIRA)" To: stdcxx-dev@incubator.apache.org Subject: [jira] Created: (STDCXX-225) deriving from std::strstreambuf causes a coredump MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N deriving from std::strstreambuf causes a coredump ------------------------------------------------- Key: STDCXX-225 URL: http://issues.apache.org/jira/browse/STDCXX-225 Project: C++ Standard Library Type: Bug Components: 27. Input/Output Environment: all Reporter: Martin Sebor 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 Reply-To: Mukesh Kapoor 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 #include #include #include 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 To: Mukesh Kapoor 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 Reply-To: Mukesh Kapoor 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. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira