diff --git a/lib/filesystem/CCompressedStream.cpp b/lib/filesystem/CCompressedStream.cpp index dad10b4aa..a76bc8b3e 100644 --- a/lib/filesystem/CCompressedStream.cpp +++ b/lib/filesystem/CCompressedStream.cpp @@ -65,10 +65,10 @@ void CBufferedStream::ensureSize(si64 size) while(static_cast(buffer.size()) < size && !endOfFileReached) { si64 initialSize = buffer.size(); - si64 currentStep = std::min(size, buffer.size()); + si64 need = size - buffer.size(); // to avoid large number of calls at start // this is often used to load h3m map headers, most of which are ~300 bytes in size - vstd::amax(currentStep, 512); + si64 currentStep = std::min(need, std::max(initialSize, si64{512})); buffer.resize(initialSize + currentStep); diff --git a/lib/mapping/MapReaderH3M.cpp b/lib/mapping/MapReaderH3M.cpp index 44e7c4ad5..3793822c8 100644 --- a/lib/mapping/MapReaderH3M.cpp +++ b/lib/mapping/MapReaderH3M.cpp @@ -199,9 +199,11 @@ RoadId MapReaderH3M::readRoad() RiverId MapReaderH3M::readRiver() { - RiverId result(readInt8()); - assert(result.getNum() <= features.riversCount); - return result; + const uint8_t raw = readInt8(); + // Keep low 3 bits as river type (0..4); discard high-bit flags set by some editors (HotA ?) + const uint8_t type = raw & 0x07; + assert(type <= features.riversCount); + return RiverId(type); } PrimarySkill MapReaderH3M::readPrimary()