all repos — mgba @ aa9994a48692a394d69061483a74cd70405ede20

mGBA Game Boy Advance Emulator

GB Memory: Prevent accessing empty SRAM (fixes #831)
Vicki Pfau vi@endrift.com
Sat, 29 Jul 2017 15:31:29 -0700
commit

aa9994a48692a394d69061483a74cd70405ede20

parent

ab5e392bbc7265a7805d9514b9193a27a89ab57e

2 files changed, 4 insertions(+), 3 deletions(-)

jump to
M CHANGESCHANGES

@@ -9,6 +9,7 @@ - GB MBC: Fix SRAM sizes 4 and 5

- GB Video: Fix 16-bit screenshots (fixes mgba.io/i/826) - GB Core: Fix palette loading when loading a foreign config - Qt: Fix LOG argument order + - GB Memory: Prevent accessing empty SRAM (fixes mgba.io/i/831) Misc: - Qt: Don't rebuild library view if style hasn't changed
M src/gb/memory.csrc/gb/memory.c

@@ -220,7 +220,7 @@ if (memory->rtcAccess) {

return memory->rtcRegs[memory->activeRtcReg]; } else if (memory->mbcRead) { return memory->mbcRead(memory, address); - } else if (memory->sramAccess) { + } else if (memory->sramAccess && memory->sram) { return memory->sramBank[address & (GB_SIZE_EXTERNAL_RAM - 1)]; } else if (memory->mbcType == GB_HuC3) { return 0x01; // TODO: Is this supposed to be the current SRAM bank?

@@ -289,7 +289,7 @@ case GB_REGION_EXTERNAL_RAM:

case GB_REGION_EXTERNAL_RAM + 1: if (memory->rtcAccess) { memory->rtcRegs[memory->activeRtcReg] = value; - } else if (memory->sramAccess) { + } else if (memory->sramAccess && memory->sram) { memory->sramBank[address & (GB_SIZE_EXTERNAL_RAM - 1)] = value; } else if (memory->mbcType == GB_MBC7) { GBMBC7Write(memory, address, value);

@@ -387,7 +387,7 @@ case GB_REGION_EXTERNAL_RAM + 1:

if (memory->rtcAccess) { return memory->rtcRegs[memory->activeRtcReg]; } else if (memory->sramAccess) { - if (segment < 0) { + if (segment < 0 && memory->sram) { return memory->sramBank[address & (GB_SIZE_EXTERNAL_RAM - 1)]; } else if ((size_t) segment * GB_SIZE_EXTERNAL_RAM < gb->sramSize) { return memory->sram[(address & (GB_SIZE_EXTERNAL_RAM - 1)) + segment *GB_SIZE_EXTERNAL_RAM];