[Bug libstdc++/39569] Apparent memory corruption in std::stringstream after calling syslog()

paolo dot carlini at oracle dot com gcc-bugzilla@gcc.gnu.org
Mon Mar 30 15:59:00 GMT 2009



------- Comment #5 from paolo dot carlini at oracle dot com  2009-03-30 15:58 -------
Your code triggers undefined behaviour here:

const char* OutBuf = reinterpret_cast<const char*>(OutStream.str().c_str());

because str() returns a temporary string, which then dies, leaving OutBuf
pointing to unallocated memory. Just copy that temporary somewhere, dunno:

std::string outstr = OutStream.str(); 
const char* OutBuf = outstr.c_str();

or something similar.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39569



More information about the Gcc-bugs mailing list