This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: strstream.h (deprecated) is broken
- From: "Michael Veksler" <VEKSLER at il dot ibm dot com>
- To: Joe Buck <Joe dot Buck at synopsys dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 31 May 2002 23:14:16 +0300
- Subject: Re: strstream.h (deprecated) is broken
- Sensitivity:
I'll file a bug report soon.
I cannot add the following line to the test case.
std::cout << s.str();
Due to strstream oddity, strstream::str() should call
strstream::rdbuf()->freeze(1). This effectively prohibits deallocation
of the buffer, and causes a memory leak. This means that the above
line would make the test case pass (the crash is in the destructor
while the buffer is being deallocated).
What would "work" is
std::cout << s.str() << std::endl; // effectivly freeze the buffer.
s.rdbuf()->freeze(0); // un-freeze the buffer to allow deallocation.
I'll try to find out what is wrong, and then file a bug report.
Joe Buck <Joe.Buck@synopsys.com> on 31/05/2002 20:42:49
Please respond to Joe Buck <Joe.Buck@synopsys.com>
To: Michael Veksler/Haifa/IBM@IBMIL
cc: gcc@gcc.gnu.org
Subject: Re: strstream.h (deprecated) is broken
> I get a segmentation fault when using strstream (yes I know it is
> deprecated, but I need to support older compilers for my customers...)
> gcc version 3.2 20020530 (experimental)
>
> $ g++ -Wno-deprecated t.cpp
> $ ./a.out
> Segmentation fault (core dumped)
> $ cat t.cpp
> #include <strstream.h>
> #include <iostream>
>
> int main()
> {
> strstream s;
> for (unsigned i=0 ; i!= 8 ; ++i)
> s << i << std::endl;
> s << std::ends;
>
> return 0;
> }
The program works in 3.1, so presumably this is a recently introduced
bug. Please file a bug report (see http://gcc.gnu.org/bugs.html).
A better test case would have something like
std::cout << s.str();
at the end.