This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.
Section: D.15.2.4 [depr.strstreambuf.virtuals] Status: NAD Submitter: Martin Sebor Opened: 2000-10-05 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [depr.strstreambuf.virtuals].
View all issues with NAD status.
Discussion:
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.
Proposed resolution:
Change the last sentence of D.15.2 [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.
[ pre-Copenhagen: Dietmar provided wording for proposed resolution. ]
[ post-Copenhagen: Fixed a typo: proposed resolution said to fix 4.7.1, not D.7.1. ]
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.