From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8135 invoked by alias); 19 Nov 2002 13:46:08 -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 8114 invoked by uid 71); 19 Nov 2002 13:46:06 -0000 Resent-Date: 19 Nov 2002 13:46:06 -0000 Resent-Message-ID: <20021119134606.8113.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, michael.pronath@gmx.de Received: (qmail 8009 invoked by uid 61); 19 Nov 2002 13:44:46 -0000 Message-Id: <20021119134446.8008.qmail@sources.redhat.com> Date: Mon, 25 Nov 2002 14:42:00 -0000 From: michael.pronath@gmx.de Reply-To: michael.pronath@gmx.de To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: libstdc++/8636: global ostringstreams lose their data X-SW-Source: 2002-11/txt/msg00947.txt.bz2 List-Id: >Number: 8636 >Category: libstdc++ >Synopsis: global ostringstreams lose their data >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Tue Nov 19 05:46:05 PST 2002 >Closed-Date: >Last-Modified: >Originator: michael.pronath@gmx.de >Release: unknown-1.0 >Organization: >Environment: Linux glibc2 g++ 3.2 both in debian package and when compiled from source >Description: global ostringstreams lose their data after calling c_str on them when new memory is allocated. See appended example. Expected output: Hello World, where are you? real output: Hello Hello Hello Hello Hell reason: when fillmystream() returns, the ostringstream content is forgotten, just like it was an automatic variable. The string operator+= then allocates new memory for extension of the string and gets the address of x and then appends itself. Interestingly, this does not happen in valgrind. >How-To-Repeat: g++ -o teststream teststream.cc ./teststream valgrind ./teststream >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: application/octet-stream; name="teststream.cc" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="teststream.cc" I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4K CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpvc3RyaW5nc3RyZWFtIHRlc3RzdHJlYW07CmNvbnN0IGNo YXIgKng7Cgp2b2lkIGZpbGxteXN0cmVhbSgpCnsKICAgdGVzdHN0cmVhbSA8PCAiIFdvcmxkLCB3 aGVyZSBhcmUgeW91PyI7CiAgIHggPSB0ZXN0c3RyZWFtLnN0cigpLmNfc3RyKCk7CiAgIHJldHVy bjsKfQogICAKaW50IG1haW4oKQp7CiAgIHN0cmluZyB0ZXN0c3RyaW5nPSIiOwogICBmaWxsbXlz dHJlYW0oKTsKICAgdGVzdHN0cmluZyA9ICJIZWxsbyAiOwogICB0ZXN0c3RyaW5nICs9IHg7CiAg IGNvdXQgPDwgInRlc3RzdHJpbmcgaXMgJyIgPDwgdGVzdHN0cmluZyA8PCAiJyIgPDwgZW5kbDsK fQoK