mirror of https://github.com/mgba-emu/mgba.git
GB Memory: Fix potential crash when directly accessing invalid SRAM
This commit is contained in:
parent
bd805dd720
commit
18b798ec41
src/gb
|
@ -474,13 +474,14 @@ uint8_t GBView8(struct SM83Core* cpu, uint16_t address, int segment) {
|
|||
if (memory->rtcAccess) {
|
||||
return memory->rtcRegs[memory->activeRtcReg];
|
||||
} else if (memory->sramAccess) {
|
||||
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];
|
||||
} else {
|
||||
return 0xFF;
|
||||
if (memory->sram) {
|
||||
if (segment < 0) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
return 0xFF;
|
||||
} else if (memory->mbcRead) {
|
||||
return memory->mbcRead(memory, address);
|
||||
} else if (memory->mbcType == GB_HuC3) {
|
||||
|
|
Loading…
Reference in New Issue