gzip: uphold rules for basic_streambuf::underflow overrides

This commit is contained in:
Emil J. Tywoniak 2025-01-09 13:38:51 +01:00
parent 00071c1cd1
commit fa8642be02
1 changed files with 6 additions and 1 deletions

View File

@ -62,8 +62,13 @@ std::istream::int_type gzip_istream::ibuf::underflow() {
log_assert(gzf && "No gzfile opened\n");
int bytes_read = Zlib::gzread(gzf, buffer, buffer_size);
if (bytes_read <= 0) {
if (Zlib::gzeof(gzf))
if (Zlib::gzeof(gzf)) {
// "On failure, the function ensures that either
// gptr() == nullptr or gptr() == egptr."
// Let's set gptr to egptr
setg(eback(), egptr(), egptr());
return traits_type::eof();
}
int err;
const char* error_msg = Zlib::gzerror(gzf, &err);