all repos — mgba @ 4e73cd32f1621d115bd22125d722113d635ee08d

mGBA Game Boy Advance Emulator

GB: Fix null unmap when resizing SRAM
Jeffrey Pfau jeffrey@endrift.com
Thu, 08 Sep 2016 19:02:39 -0700
commit

4e73cd32f1621d115bd22125d722113d635ee08d

parent

74df1d1531114305847b4c23b742db712add126f

1 files changed, 9 insertions(+), 3 deletions(-)

jump to
M src/gb/gb.csrc/gb/gb.c

@@ -123,7 +123,9 @@ if (vf->size(vf) & 0xFF) {

// Copy over appended data, e.g. RTC data memcpy(extdataBuffer, &gb->memory.sram[gb->sramSize - (vf->size(vf) & 0xFF)], vf->size(vf) & 0xFF); } - vf->unmap(vf, gb->memory.sram, gb->sramSize); + if (gb->memory.sram) { + vf->unmap(vf, gb->memory.sram, gb->sramSize); + } vf->truncate(vf, size); gb->memory.sram = vf->map(vf, size, MAP_WRITE); memset(&gb->memory.sram[gb->sramSize], 0xFF, size - gb->sramSize);

@@ -131,11 +133,15 @@ if (size & 0xFF) {

memcpy(&gb->memory.sram[gb->sramSize - (size & 0xFF)], extdataBuffer, size & 0xFF); } } else { - vf->unmap(vf, gb->memory.sram, gb->sramSize); + if (gb->memory.sram) { + vf->unmap(vf, gb->memory.sram, gb->sramSize); + } gb->memory.sram = vf->map(vf, size, MAP_WRITE); } } else { - vf->unmap(vf, gb->memory.sram, gb->sramSize); + if (gb->memory.sram) { + vf->unmap(vf, gb->memory.sram, gb->sramSize); + } gb->memory.sram = vf->map(vf, size, MAP_READ); } } else {