public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Michael Pronath <michael.pronath@gmx.de>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: libstdc++/8636: global ostringstreams lose their data
Date: Sat, 30 Nov 2002 20:56:00 -0000 [thread overview]
Message-ID: <20021121121602.4142.qmail@sources.redhat.com> (raw)
The following reply was made to PR libstdc++/8636; it has been noted by GNATS.
From: Michael Pronath <michael.pronath@gmx.de>
To: Paolo Carlini <pcarlini@unitus.it>
Cc: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
nobody@gcc.gnu.org
Subject: Re: libstdc++/8636: global ostringstreams lose their data
Date: 21 Nov 2002 13:11:49 +0100
Hello again,
I think I found the reason for this, it's not a bug.
If 'oss' is an ostringstream, then calling
x = oss.str().c_str();
is a bad idea, because oss.str() returns a copy of the contents of oss
by value, i.e. a temporary value that is free'd right after this
statement. Therefore x is invalid, pointing to a free'd memory region.
--> oss.str().c_str() will always return a pointer to a temporary
value.
For example, strcpy(dest, oss.str().c_str()) would work, but
not x=oss.str().c_str(); strcpy(dest,x);
I believe this is ok with the standard.
Sorry, my fault.
Regards,
Michael
next reply other threads:[~2002-11-21 12:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-30 20:56 Michael Pronath [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-11-30 20:01 Paolo Carlini
2002-11-28 8:06 paolo
2002-11-25 14:42 michael.pronath
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20021121121602.4142.qmail@sources.redhat.com \
--to=michael.pronath@gmx.de \
--cc=gcc-prs@gcc.gnu.org \
--cc=nobody@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).