The problem appears to be in the code that calls setp inside the indirect_streambuf. It seems to be using incorrect pointers.
Can someone confirm my thinking here?
I changed this function from this:
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::sync_impl()
{
std::streamsize avail, amt;
if ((avail = static_cast<std::streamsize>(pptr() - pbase())) > 0) {
if ((amt = obj().write(pbase(), avail, next())) == avail)
setp(out().begin(), out().end());
else {
const char_type* ptr = pptr();
setp(out().begin() + amt, out().end());
pbump(ptr - pptr());
}
}
}
to this:
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::sync_impl()
{
std::streamsize avail, amt;
if ((avail = static_cast<std::streamsize>(pptr() - pbase())) > 0) {
if ((amt = obj().write(pbase(), avail, next())) == avail)
setp(out().begin(), out().end());
else {
const char_type* ptr = pptr();
setp(pbase() + amt, epptr());
pbump(ptr - pptr());
}
}
}
My unit tests now pass. I have several other tests using chained filters and their unit tests now pass, when they did not before.
I appreciate any other eyes put on this.