This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/8466: basic_stringbuf::str(basic_string const:) modifies its argument


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]