From 9012f5426f37ce454c07a3bbc7a5a719866c9ab1 Mon Sep 17 00:00:00 2001 From: rogerman Date: Sat, 29 Oct 2011 20:18:55 +0000 Subject: [PATCH] Cheat System: - Fixed a crashing bug in certain situations when if a bad AR cheat code is applied, would then cause an invalid memory access. --- desmume/src/cheatSystem.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index 78b89f93a..fd1e6d5c9 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -378,13 +378,18 @@ void CHEATS::ARparser(CHEATS_LIST& list) { u8 *tmp_code = (u8*)(list.code[i+1]); u32 addr = hi+offset; - - for (u32 t = 0; t < lo; t++) + u32 maxByteReadLocation = ((2 * 4) * (MAX_XX_CODE - i - 1)) - 1; // 2 = 2 array dimensions, 4 = 4 bytes per array element + + if (lo <= maxByteReadLocation) { - u8 tmp = tmp_code[t]; - _MMU_write08(addr, tmp); - addr++; + for (u32 t = 0; t < lo; t++) + { + u8 tmp = tmp_code[t]; + _MMU_write08(addr, tmp); + addr++; + } } + i += (lo / 8); } break;