public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Paolo Carlini <pcarlini@unitus.it>
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:01:00 -0000 [thread overview]
Message-ID: <20021121105602.20793.qmail@sources.redhat.com> (raw)
The following reply was made to PR libstdc++/8636; it has been noted by GNATS.
From: Paolo Carlini <pcarlini@unitus.it>
To: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
nobody@gcc.gnu.org
Cc: michael.pronath@gmx.de
Subject: Re: libstdc++/8636: global ostringstreams lose their data
Date: Thu, 21 Nov 2002 11:53:59 +0100
Yes, the problem is present with g++-3.0, g++-3.2 and g++-3.2.1
all with glibc2.3.1
Debian system: libc6_2.3.1-3
g++-3.2_3.2.1-0pre2
g++-3.0_3.0.4-7
libstdc++5-dev_3.2.1-0pre2
Redhat system: glibc-devel-2.1.3-22
glibc-2.1.3-22
g++-3.2 self-made
The original topic was wrong, I found an even simpler example, it's got
nothing to do with global/local variables; it's probably in the
allocator:
-----------------------------------------------------------------------
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
const char *x;
ostringstream teststream;
string teststring="";
teststream << "World, where are you?";
x = teststream.str().c_str();
teststring = "Hello ";
teststring += x;
cout << "teststring is '" << teststring << "'." << endl;
cout << "teststream.str() is '" << teststream.str() << "'." << endl;
cout << "teststring.data() is at 0x" << hex << (int) teststring.data()
<< ", x is at 0x" << hex << (int) x << endl;
cout << "teststream.str().c_str() is at 0x" << hex
<< (int) teststream.str().c_str() << endl;
}
------------------------------------------------------------------------
g++-3.2 -o teststream teststream.cc
ldd teststream
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x4001a000)
libm.so.6 => /lib/libm.so.6 (0x400c4000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x400e5000)
libc.so.6 => /lib/libc.so.6 (0x400ed000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
Unexpected output:
teststring is 'Hello Hello Hello Hello Hello Hel'.
teststream.str() is 'World, where are you?'.
teststring.data() is at 0x804a99c, x ist at 0x804a99c
teststream.str().c_str() is at 0x804a94c
I thinks it's that the operator+= of string is resizing the string
because it needs new space to append. From the allocator, it receives
the address of "x" as if this space was already freed by the
ostringstream (don't know why). Then the string appends its data to
itself, which leads to the repeating Hello.
Regards,
Michael
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8636
next reply other threads:[~2002-11-21 10:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-30 20:01 Paolo Carlini [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-11-30 20:56 Michael Pronath
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=20021121105602.20793.qmail@sources.redhat.com \
--to=pcarlini@unitus.it \
--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).