From 722888ae66742427456a9ddd3337ff36ef559ddb Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 29 Dec 2018 19:06:24 +0000 Subject: [PATCH] Correct ROM loading issue discovered while resurrecting NES support. Signed-off-by: Adrian Conlon --- src/Rom.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Rom.cpp b/src/Rom.cpp index 25204ee..0fee3cb 100644 --- a/src/Rom.cpp +++ b/src/Rom.cpp @@ -59,9 +59,16 @@ int EightBit::Rom::load(const std::string& path, const int writeOffset, const in } int EightBit::Rom::load(const std::vector& bytes, const int writeOffset, const int readOffset, int limit) { + if (limit < 0) limit = bytes.size() - readOffset; - std::copy(bytes.cbegin() + readOffset, bytes.cbegin() + limit, m_bytes.begin() + writeOffset); + + const size_t extent = limit + writeOffset; + if (m_bytes.size() < extent) + m_bytes.resize(extent); + + std::copy(bytes.cbegin() + readOffset, bytes.cbegin() + readOffset + limit, m_bytes.begin() + writeOffset); + return limit; }