Farid Zaripov wrote:
-----Original Message-----
From: Martin Sebor (JIRA) [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 24, 2007 1:14 AM
To: stdcxx-dev@incubator.apache.org
Subject: [jira] Created: (STDCXX-427) SIGSEGV in istringstream::str()
SIGSEGV in istringstream::str()
-------------------------------
Key: STDCXX-427
URL: https://issues.apache.org/jira/browse/STDCXX-427
Project: C++ Standard Library
Issue Type: Bug
Components: 27. Input/Output
Affects Versions: 4.2
Environment: gcc-3.3.3 on Linux
Reporter: Martin Sebor
Priority: Critical
This only happens on trunk, not with 4.1.3:
$ rm t.o && cat t.cpp && make t && gdb -q t #include
<cassert> #include <sstream> #include <string>
int main ()
{
using namespace std;
string str ("test");
istringstream isstr;
isstr.str (str);
assert (isstr.str ().length () == str.length ());
assert (isstr.str () == str);
}
The bug also reproduced on MSVC. The proposed patch below:
Thanks for looking into it!
I'm not sure your proposed patch is correct or necessary
(although I'm not saying the original code is correct either).
In fact, I'm not sure the other overload of str(), i.e., the
one that sets the string buffer, is correct either and I
suspect that might be the root of the problem. The function
should assert(this->_C_is_valid()) as a postcondition (and
the overload below should do the same as a precondition) to
verify that the buffer is in a stable and consistent state.
Let's see if the assertion passes first before considering
this patch further.
Martin
-----------------------
Index: sstream
===================================================================
--- sstream (revision 541218)
+++ sstream (working copy)
@@ -126,7 +126,7 @@
_C_string_type str () const {
const _RWSTD_SIZE_T __slen = (this->egptr () < this->pptr () ?
- this->pptr () : this->egptr ()) - this->pbase ();
+ this->pptr () : this->egptr ()) - this->_C_buffer;
return _C_string_type (this->_C_buffer, __slen);
}
-----------------------
Farid.