Title
interaction of strstreambuf::overflow() and seekoff()
Status
nad
Section
[depr.strstreambuf.virtuals]
Submitter
Martin Sebor

Created on 2000-10-05.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

This is related to issue 65: it's not clear what it means to seek beyond the current area. Without resolving issue 65 we can't resolve this. As with issue 65, the library working group does not wish to invest time nailing down corner cases in a deprecated feature.

Date: 2010-10-21.18:28:33

[ post-Copenhagen: Fixed a typo: proposed resolution said to fix 4.7.1, not D.7.1. ]

Date: 2010-10-21.18:28:33

[ pre-Copenhagen: Dietmar provided wording for proposed resolution. ]

Date: 2010-10-21.18:28:33

Proposed resolution:

Change the last sentence of [depr.strstreambuf] paragraph 4 from

Otherwise, seeklow equals gbeg and seekhigh is either pend, if pend is not a null pointer, or gend.

to become

Otherwise, seeklow equals gbeg and seekhigh is either gend if 0 == pptr(), or pbase() + max where max is the maximum value of pptr() - pbase() ever reached for this stream.

Date: 2000-10-05.00:00:00

It appears that the interaction of the strstreambuf members overflow() and seekoff() can lead to undefined behavior in cases where defined behavior could reasonably be expected. The following program demonstrates this behavior:

    #include <strstream>

    int main ()
    {
         std::strstreambuf sb;
         sb.sputc ('c');

         sb.pubseekoff (-1, std::ios::end, std::ios::in);
         return !('c' == sb.sgetc ());
    }

D.7.1.1, p1 initializes strstreambuf with a call to basic_streambuf<>(), which in turn sets all pointers to 0 in 27.5.2.1, p1.

27.5.2.2.5, p1 says that basic_streambuf<>::sputc(c) calls overflow(traits::to_int_type(c)) if a write position isn't available (it isn't due to the above).

D.7.1.3, p3 says that strstreambuf::overflow(off, ..., ios::in) makes at least one write position available (i.e., it allows the function to make any positive number of write positions available).

D.7.1.3, p13 computes newoff = seekhigh - eback(). In D.7.1, p4 we see seekhigh = epptr() ? epptr() : egptr(), or seekhigh = epptr() in this case. newoff is then epptr() - eback().

D.7.1.4, p14 sets gptr() so that gptr() == eback() + newoff + off, or gptr() == epptr() + off holds.

If strstreambuf::overflow() made exactly one write position available then gptr() will be set to just before epptr(), and the program will return 0. Buf if the function made more than one write position available, epptr() and gptr() will both point past pptr() and the behavior of the program is undefined.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2058
2010-10-21 18:28:33adminsetmessages: + msg2057
2010-10-21 18:28:33adminsetmessages: + msg2056
2010-10-21 18:28:33adminsetmessages: + msg2055
2000-10-05 00:00:00admincreate