diff --git a/src/memstreambuf.cpp b/src/memstreambuf.cpp index d24c87b..61ec8c8 100644 --- a/src/memstreambuf.cpp +++ b/src/memstreambuf.cpp @@ -54,24 +54,25 @@ std::streamsize sc::io::memstreambuf::xsputn(const char* /*s*/, std::streamsize std::streambuf::pos_type sc::io::memstreambuf::seekoff(std::streambuf::off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which) { + uint64_t pos {0}; if (which & std::ios::in) { // reading switch (dir) { case std::ios::beg: if (off < 0 || static_cast(off) > _size) return EOF; - setg(_mem, _mem + off, _mem + _size); + pos = off; break; case std::ios::cur: { - int64_t pos = gptr() - _mem + off; - if (pos < 0 || static_cast(pos) > _size) return EOF; - setg(_mem, gptr() + off, _mem + _size); + int64_t spos = gptr() - _mem + off; + if (spos < 0 || static_cast(spos) > _size) return EOF; + pos = static_cast(spos); break; } case std::ios::end: - if (off > 0 || static_cast(off) < -_size) return EOF; - setg(_mem, _mem + _size + off - 1, _mem + _size); + if (off > 0 || static_cast(_size) < -off) return EOF; + pos = _size + off - 1; break; } - return gptr() - _mem; + setg(_mem, _mem + pos, _mem + _size); } if (which & std::ios::out) { // writing switch (dir) { // TODO @@ -82,9 +83,8 @@ std::streambuf::pos_type sc::io::memstreambuf::seekoff(std::streambuf::off_type case std::ios::end: break; } - return pptr() - _mem; } - return EOF; + return pos; } std::streambuf::pos_type sc::io::memstreambuf::seekpos(std::streambuf::pos_type pos,