all repos — mgba @ 6ad402170c148bf6668e49767eceee040342a540

mGBA Game Boy Advance Emulator

GBA: Fix ROM size check
Jeffrey Pfau jeffrey@endrift.com
Tue, 02 Jun 2015 22:20:19 -0700
commit

6ad402170c148bf6668e49767eceee040342a540

parent

c0818c3a0c68b872441d0f4b6ddf491f47736bc1

1 files changed, 2 insertions(+), 1 deletions(-)

jump to
M src/gba/serialize.csrc/gba/serialize.c

@@ -106,7 +106,8 @@ if (state->audio.ch4.envelopeNextStep < 0 || state->audio.ch4.nextEvent < 0) {

GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: audio channel 4 register is negative"); return; } - if (state->cpu.gprs[ARM_PC] == BASE_CART0 || (state->cpu.gprs[ARM_PC] & SIZE_CART0) >= gba->memory.romSize) { + int region = (state->cpu.gprs[ARM_PC] >> BASE_OFFSET); + if ((region == REGION_CART0 || region == REGION_CART1 || region == REGION_CART2) && ((state->cpu.gprs[ARM_PC] - WORD_SIZE_ARM) & SIZE_CART0) >= gba->memory.romSize - WORD_SIZE_ARM) { GBALog(gba, GBA_LOG_WARN, "Savestate created using a differently sized version of the ROM"); return; }