You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Liviu Nicoara <ni...@roguewave.com> on 2006/05/03 22:37:27 UTC

std::strstreambuf fails to correctly set stream position

Hi,

The following test case fails with the latest dev stdcxx (*):

tmp$ cat t.cpp

#include <assert.h>

#include <iosfwd>
#include <strstream>

int main ()
{
    std::strstreambuf sb;
    std::ostream  os (&sb);

    os << " ";
    std::streampos pos =
        sb.pubseekoff (0, std::ios::end, std::ios::out);
    assert (pos == 1);

    return 0;
}

I ran it in an 11s build on Linux and it asserts - pos is coming back as
128 (coincidentally the size of our implementation's buffer, 16 for gcc,
512 for aCC, 128 for SunPro).

The reason for this seems to be D.7.1 p4:

"Each object of class strstreambuf has a seekable area, delimited by the
pointers seeklow and seekhigh. If gnext is a null pointer, the seekable
area is undefined. *Otherwise, seeklow equals gbeg and seekhigh is
either pend, if pend is not a null pointer, or gend.*"

The specification for seekhi seems to be incorrect - seekhi should be
the last initialized character in the controlled sequence.

Liviu

(*) The failure is also present in GNU libstdc++ (gcc 4.1.0), SunPro's
C++ Standard Library (5.3 through 5.8), HP aCC 3.63's stdlib but not
Dinkumware (AIX 5.3 w/ VisualAge for C++ 8.0, Windows XP w/ MSVC 7.1 and
8.0).

Re: std::strstreambuf fails to correctly set stream position

Posted by Martin Sebor <se...@roguewave.com>.
Liviu Nicoara wrote:
> Hi,
> 
> The following test case fails with the latest dev stdcxx (*):
> 
> tmp$ cat t.cpp
> 
> #include <assert.h>
> 
> #include <iosfwd>
> #include <strstream>
> 
> int main ()
> {
>     std::strstreambuf sb;
>     std::ostream  os (&sb);
> 
>     os << " ";
>     std::streampos pos =
>         sb.pubseekoff (0, std::ios::end, std::ios::out);
>     assert (pos == 1);
> 
>     return 0;
> }
> 
> I ran it in an 11s build on Linux and it asserts - pos is coming back as
> 128 (coincidentally the size of our implementation's buffer, 16 for gcc,
> 512 for aCC, 128 for SunPro).
> 
> The reason for this seems to be D.7.1 p4:
> 
> "Each object of class strstreambuf has a seekable area, delimited by the
> pointers seeklow and seekhigh. If gnext is a null pointer, the seekable
> area is undefined. *Otherwise, seeklow equals gbeg and seekhigh is
> either pend, if pend is not a null pointer, or gend.*"
> 
> The specification for seekhi seems to be incorrect - seekhi should be
> the last initialized character in the controlled sequence.

That's quite possible. There is an open issue about seekoff()
in stringbuf which looks related to what you're pointing out:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#563

Unfortunately the C++ committee has been reluctant to invest time
and effort into fixing problems in the deprecated stream classes
so it's unlikely that the current requirements will change. Let
me raise it on the reflector to see if there's any willingness
to fix this.

Martin

> 
> Liviu
> 
> (*) The failure is also present in GNU libstdc++ (gcc 4.1.0), SunPro's
> C++ Standard Library (5.3 through 5.8), HP aCC 3.63's stdlib but not
> Dinkumware (AIX 5.3 w/ VisualAge for C++ 8.0, Windows XP w/ MSVC 7.1 and
> 8.0).