From 7baeb26e32d5c6aeaca0a47e72bbb605b2961882 Mon Sep 17 00:00:00 2001 From: Jesse Talavera Date: Mon, 19 May 2025 19:00:48 -0400 Subject: [PATCH] Fix undefined behavior when indexing into `ARCode::Code` (#2331) - Indexing past the end of a `std::vector`'s length is undefined, even if there's extra capacity - GCC 15 introduced an assert in `vector::operator[]`, so this line caused an abort if melonDS was built with GCC 15 - It was always undefined, but now the STL checks for it --- src/AREngine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AREngine.cpp b/src/AREngine.cpp index bdda5863..0c37b321 100644 --- a/src/AREngine.cpp +++ b/src/AREngine.cpp @@ -58,7 +58,8 @@ void AREngine::RunCheat(const ARCode& arcode) for (;;) { - if (code >= &arcode.Code[arcode.Code.size()]) + if (code > &arcode.Code[arcode.Code.size() - 1]) + // If the instruction pointer is past the end of the cheat code... break; u32 a = *code++;