GB: Fix null unmap when resizing SRAM
Jeffrey Pfau jeffrey@endrift.com
Thu, 08 Sep 2016 19:02:39 -0700
1 files changed,
9 insertions(+),
3 deletions(-)
jump to
M
src/gb/gb.c
→
src/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 {