diff --git a/src/audio/chunk_load.cpp b/src/audio/chunk_load.cpp index c076c1bdb..782b70ca3 100644 --- a/src/audio/chunk_load.cpp +++ b/src/audio/chunk_load.cpp @@ -214,7 +214,12 @@ optional try_load_gme(tcb::span data) optional srb2::audio::try_load_chunk(tcb::span data) { - optional ret; + optional ret = nullopt; + + if (data.size() == 0) + { + return ret; + } ret = try_load_dmx(data); if (ret) @@ -232,5 +237,5 @@ optional srb2::audio::try_load_chunk(tcb::span data) if (ret) return ret; - return nullopt; + return ret; } diff --git a/src/io/streams.hpp b/src/io/streams.hpp index ede48f0a9..39f0b6299 100644 --- a/src/io/streams.hpp +++ b/src/io/streams.hpp @@ -431,10 +431,10 @@ public: head = offset; break; case SeekFrom::kEnd: - if (-offset >= static_cast(span_.size())) { + if (static_cast(span_.size()) + offset < 0) { throw std::logic_error("end offset is out of bounds"); } - head = span_.size() - offset; + head = span_.size() + offset; break; case SeekFrom::kCurrent: if (head_ + offset < 0) { @@ -526,10 +526,10 @@ public: head = offset; break; case SeekFrom::kEnd: - if (-offset >= static_cast(vec_.size())) { + if (static_cast(vec_.size()) + offset < 0) { throw std::logic_error("end offset is out of bounds"); } - head = vec_.size() - offset; + head = vec_.size() + offset; break; case SeekFrom::kCurrent: if (head_ + offset < 0) {