From 53dba3bba9987614bf5b105520065b5f7e4f8617 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sun, 29 May 2022 16:40:17 -0230 Subject: [PATCH] Fix a few array out of bounds accesses (fixes #806). Note that this applies to mainline too, not just libretro. --- Makefile | 1 + src/debugger/CartDebug.hxx | 2 +- src/emucore/Cart.cxx | 8 +++----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 771125958..23b5d6c2b 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ srcdir ?= . +# -Wp,-D_GLIBCXX_ASSERTIONS DEFINES := -DSDL_SUPPORT -D_GLIBCXX_USE_CXX11_ABI=1 LDFLAGS := -pthread INCLUDES := diff --git a/src/debugger/CartDebug.hxx b/src/debugger/CartDebug.hxx index 16ec41e16..da8f4b450 100644 --- a/src/debugger/CartDebug.hxx +++ b/src/debugger/CartDebug.hxx @@ -300,7 +300,7 @@ class CartDebug : public DebuggerSystem struct ReservedEquates { std::array TIARead; std::array TIAWrite; - std::array IOReadWrite; + std::array IOReadWrite; std::array ZPRAM; AddrToLabel Label{}; bool breakFound{false}; diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index ed57ff42e..974b20e39 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -133,15 +133,13 @@ void Cartridge::pokeRAM(uInt8& dest, uInt16 address, uInt8 value) void Cartridge::createRomAccessArrays(size_t size) { myAccessSize = static_cast(size); -#ifdef DEBUGGER_SUPPORT + + // Always create ROM access base even if DEBUGGER_SUPPORT is disabled, + // since other parts of the code depend on it existing myRomAccessBase = make_unique(size); std::fill_n(myRomAccessBase.get(), size, Device::ROW); myRomAccessCounter = make_unique(size * 2); std::fill_n(myRomAccessCounter.get(), size * 2, 0); -#else - myRomAccessBase = nullptr; - myRomAccessCounter = nullptr; -#endif } #ifdef DEBUGGER_SUPPORT