Opened 8 years ago
#10809 new Bugs
Seeking breaks iostreams::restriction<std::istream> internal state
Reported by: | Owned by: | Jonathan Turkanis | |
---|---|---|---|
Milestone: | To Be Determined | Component: | iostreams |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | Cc: |
Description
As in the attached test case, calling seekg() on a restricted istream appears to break the internal state such that more characters can be extracted than expected.
I've done some digging around, and I think this is because the restriction device does a seek relative to std::ios_base::cur, which returns -1 from the underlying implementation: Calling std::streambuf::pubseekoff() with way = ios_base::cur and which = (ios_base::in | ios_base::out) fails according to the C++ standard section 27.8.2.4.
When fixing this, it's worth noting that calling pubseekoff() will also fail with libstdc++ if it's passed (ios_base::in | ios_base::out) when the stream buffer has only an output buffer or input buffer, but not both.
Tested with g++-4.6.3 and g++-4.8.? on 64 bit linux Ubuntu. Behaviour is consistent with clang++-libc++, but inconsistent with MSVC.
Test case showing the bad behaviour