You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by "Martin Sebor (JIRA)" <ji...@apache.org> on 2006/06/28 20:25:29 UTC
[jira] Created: (STDCXX-225) deriving from std::strstreambuf causes
a coredump
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 <Mu...@Sun.COM>
Reply-To: Mukesh Kapoor <Mu...@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 <se...@roguewave.com>
To: Mukesh Kapoor <Mu...@Sun.COM>
CC: oemsupport@roguewave.com
References: <20...@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 <Mu...@Sun.COM>
Reply-To: Mukesh Kapoor <Mu...@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.
-
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
[jira] Resolved: (STDCXX-225) deriving from std::strstreambuf
causes a coredump
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/STDCXX-225?page=all ]
Martin Sebor resolved STDCXX-225.
---------------------------------
Fix Version/s: 4.2
Resolution: Fixed
Test case runs to completion with the latest trunk. Not sure why this is still open. Resolving as fixed.
> deriving from std::strstreambuf causes a coredump
> -------------------------------------------------
>
> Key: STDCXX-225
> URL: http://issues.apache.org/jira/browse/STDCXX-225
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 27. Input/Output
> Environment: all
> Reporter: 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 <Mu...@Sun.COM>
> Reply-To: Mukesh Kapoor <Mu...@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 <se...@roguewave.com>
> To: Mukesh Kapoor <Mu...@Sun.COM>
> CC: oemsupport@roguewave.com
> References: <20...@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 <Mu...@Sun.COM>
> Reply-To: Mukesh Kapoor <Mu...@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.
-
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
[jira] Closed: (STDCXX-225) deriving from std::strstreambuf causes
a coredump
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ 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 <Mu...@Sun.COM>
> Reply-To: Mukesh Kapoor <Mu...@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 <se...@roguewave.com>
> To: Mukesh Kapoor <Mu...@Sun.COM>
> CC: oemsupport@roguewave.com
> References: <20...@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 <Mu...@Sun.COM>
> Reply-To: Mukesh Kapoor <Mu...@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.