From 2243ec5b31dd3d14ebf3043f2037448b727194f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 13 Feb 2023 15:41:32 +0100 Subject: [PATCH] Clearing fixes, fix out-of-bounds iterator --- Core/SaveState.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 50b3dad39d..a8fc0dae14 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -228,7 +228,11 @@ namespace SaveState int blockSize = std::min(BLOCK_SIZE, (int)(compressed.size() - i)); result.insert(result.end(), compressed.begin() + i, compressed.begin() + i + blockSize); i += blockSize; - basePos += blockSize; + // This check is to avoid advancing basePos out of range, which MSVC catches. + // When this happens, we're at the end of decoding anyway. + if (base.end() - basePos >= blockSize) { + basePos += blockSize; + } } } } @@ -242,6 +246,18 @@ namespace SaveState std::lock_guard guard(lock_); first_ = 0; next_ = 0; + for (auto &b : bases_) { + b.clear(); + } + baseMapping_.clear(); + baseMapping_.resize(size_); + for (auto &s : states_) { + s.clear(); + } + buffer_.clear(); + base_ = -1; + baseUsage_ = 0; + rewindLastTime = time_now_d(); } bool Empty() const