1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

fix CBufferedStream::ensureSize growth & read semantics (compat for 'A War' map)

This commit is contained in:
Michał Zaremba
2025-10-11 09:26:14 +02:00
parent ace5425433
commit d2ac0fd4ff
2 changed files with 7 additions and 5 deletions

View File

@@ -65,10 +65,10 @@ void CBufferedStream::ensureSize(si64 size)
while(static_cast<si64>(buffer.size()) < size && !endOfFileReached) while(static_cast<si64>(buffer.size()) < size && !endOfFileReached)
{ {
si64 initialSize = buffer.size(); si64 initialSize = buffer.size();
si64 currentStep = std::min<si64>(size, buffer.size()); si64 need = size - buffer.size();
// to avoid large number of calls at start // 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 // 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<si64>(need, std::max<si64>(initialSize, si64{512}));
buffer.resize(initialSize + currentStep); buffer.resize(initialSize + currentStep);

View File

@@ -199,9 +199,11 @@ RoadId MapReaderH3M::readRoad()
RiverId MapReaderH3M::readRiver() RiverId MapReaderH3M::readRiver()
{ {
RiverId result(readInt8()); const uint8_t raw = readInt8();
assert(result.getNum() <= features.riversCount); // Keep low 3 bits as river type (0..4); discard high-bit flags set by some editors (HotA ?)
return result; const uint8_t type = raw & 0x07;
assert(type <= features.riversCount);
return RiverId(type);
} }
PrimarySkill MapReaderH3M::readPrimary() PrimarySkill MapReaderH3M::readPrimary()