From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4178 invoked by alias); 21 Nov 2002 12:16:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 4143 invoked by uid 71); 21 Nov 2002 12:16:02 -0000 Date: Sat, 30 Nov 2002 20:56:00 -0000 Message-ID: <20021121121602.4142.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Michael Pronath Subject: Re: libstdc++/8636: global ostringstreams lose their data Reply-To: Michael Pronath X-SW-Source: 2002-11/txt/msg01213.txt.bz2 List-Id: The following reply was made to PR libstdc++/8636; it has been noted by GNATS. From: Michael Pronath To: Paolo Carlini 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