> -----Original Message-----
> From: Martin Sebor [mailto:[EMAIL PROTECTED]
> Sent: Saturday, May 26, 2007 3:05 AM
> To: [email protected]
> Subject: Re: [PATCH] RE: [jira] Created: (STDCXX-427) SIGSEGV
> in istringstream::str()
>
> In input mode (only) the function is supposed to return:
>
> string(eback(), egptr());
>
> In output mode (or input | output) the function must return:
>
> string(pbase(), high_mark);
>
> So unless I'm missing something the program below should be a
> valid (albeit incomplete) test case. Let me know what you think.
>
> #include <cassert>
> #include <cstdio>
> #include <sstream>
>
> int main ()
> {
> struct Buf: std::stringbuf {
> Buf (std::string s, std::ios::openmode m)
> : std::stringbuf (s, m) { }
>
> void setget (int beg, int cur, int end) {
> setg (eback () + beg, eback () + cur, eback () + end);
> }
>
> void setput (int beg, int cur, int end) {
> setp (pbase () + beg, pbase () + end);
> pbump (cur);
> }
> };
>
> {
> Buf buf ("abcde", std::ios::in);
> buf.setget (1, 2, 4);
> std::printf ("%s\n", buf.str ().c_str ());
> assert ("bcd" == buf.str ());
> }
> {
> Buf buf ("abcde", std::ios::out);
> buf.setput (1, 2, 4);
Here setput() doesn't change the highmark, because highmark
points past to the
last initialized character (in this case points past the 'e') , and
buf.str() will return "bcde".
> std::printf ("%s\n", buf.str ().c_str ());
> assert ("bcd" == buf.str ());
> }
> }
Farid.