The 'c_str()' method of the STL 'basic_string' class template returns a pointer to free memory when called against a string returned by the 'str()' method of the 'basic_ostringstream' class template. ISO/IEC 14882 [21.3.6] indicates pointers returned by 'c_str()' should be good until the next non-const member of the string object is called.
This behavior is confirmed by both 'purify' and 'mudflap'. The same test case runs clean with 'purify' on Solaris 8 with the Sun Studio 5.4 compiler. -- Summary: ostringstream::str().c_str() returns pointer to unallocated memory Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: major Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: lawless at spamcop dot net GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25719