This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/25719] ostringstream::str().c_str() returns pointer to unallocated memory
- From: "pcarlini at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 9 Jan 2006 10:26:04 -0000
- Subject: [Bug libstdc++/25719] ostringstream::str().c_str() returns pointer to unallocated memory
- References: <bug-25719-7638@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from pcarlini at suse dot de 2006-01-09 10:26 -------
The problem in your code, which makes it illegal, in general, is not c_str(),
which indeed is used correctly, but str(): it generates a temporary (note that
it returns by **value**, e.g., doesn't return a reference to a string object
inside the stream), which dies, correctly, before printit is called. There are
many ways to deal with the issue, perhaps you can first assign the string
returned by str() to a local string.
--
pcarlini at suse dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25719