public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: gnats@kayari.org
To: gcc-gnats@gcc.gnu.org
Subject: libstdc++/8466: basic_stringbuf::str(basic_string const:) modifies its argument
Date: Tue, 05 Nov 2002 12:06:00 -0000	[thread overview]
Message-ID: <200211051956.gA5JuFg03783@holyghost.redi.uklinux.net> (raw)


>Number:         8466
>Category:       libstdc++
>Synopsis:       basic_stringbuf::str(basic_string const&) modifies its argument
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 05 12:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jonathan Wakely
>Release:        3.3 20021021 (experimental)
>Organization:
>Environment:
System: Linux holyghost.redi.uklinux.net 2.4.19 #44 Thu Aug 8 23:05:18 BST 2002 i586 unknown
Architecture: i586

	
host: i586-pc-linux-gnu
build: i586-pc-linux-gnu
target: i586-pc-linux-gnu
configured with: ../gcc/configure --prefix=/home/redi --enable-languages=c,c++ --program-suffix=3x --disable-nls
>Description:

The program below aborts on the second assertion, but I believe it should
finish normally. The basic_stringbuf::str() overload taking an argument
should copy the string's contents to the buffer, instead it appears to be
sharing the string's internal representation so that writing to the stream
modifies the (possibly const) string.

>How-To-Repeat:

Run the following program:

    #include <sstream>
    #include <cassert>

    int main()
    {
        const char* orig = "0123456789";
        const std::string s = orig;

        std::ostringstream o(s);
        o << "abcde";
        assert(s == orig);  // PASS

        o.str(s);
        o << "abcde";
        assert(s == orig);  // FAIL! const string was modified!
    }

This gives:
    a.out: sstream_buf_share.cc:15: int main(): Assertion `s == orig' failed.

>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-11-05 20:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-05 12:06 gnats [this message]
2002-11-05 13:34 libstdc++/8466: basic_stringbuf::str(basic_string const&) " paolo
2002-11-05 15:36 paolo

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=200211051956.gA5JuFg03783@holyghost.redi.uklinux.net \
    --to=gnats@kayari.org \
    --cc=gcc-gnats@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).