GBA Savedata: Fix crash when resizing flash save games for RTC data

This commit is contained in:
Vicki Pfau 2023-11-22 03:57:13 -08:00
parent ef9c5bd096
commit 0e3d55c2ac
2 changed files with 10 additions and 0 deletions

View File

@ -13,6 +13,7 @@ Emulation fixes:
- GBA BIOS: Fix clobbering registers with word-sized CpuSet
- GBA SIO: Fix normal mode SI/SO semantics (fixes mgba.io/i/2925)
Other fixes:
- GBA Savedata: Fix crash when resizing flash save games for RTC data
- mGUI: Fix cases where an older save state screenshot would be shown (fixes mgba.io/i/2183)
- Qt: Re-enable sync for multiplayer windows that aren't connected (fixes mgba.io/i/2974)
- Qt: Fix mute settings not being loaded on setting screen (fixes mgba.io/i/2990)

View File

@ -602,14 +602,23 @@ void GBASavedataRTCWrite(struct GBASavedata* savedata) {
size_t size = GBASavedataSize(savedata);
savedata->vf->seek(savedata->vf, size & ~0xFF, SEEK_SET);
int bank = 0;
if ((savedata->vf->size(savedata->vf) & 0xFF) != sizeof(buffer)) {
// Writing past the end of the file can invalidate the file mapping
if (savedata->type == SAVEDATA_FLASH1M) {
bank = savedata->currentBank == &savedata->data[0x10000];
}
savedata->vf->unmap(savedata->vf, savedata->data, size);
savedata->data = NULL;
}
savedata->vf->write(savedata->vf, &buffer, sizeof(buffer));
if (!savedata->data) {
savedata->data = savedata->vf->map(savedata->vf, size, MAP_WRITE);
if (savedata->type == SAVEDATA_FLASH1M) {
savedata->currentBank = &savedata->data[bank << 16];
} else if (savedata->type == SAVEDATA_FLASH512) {
savedata->currentBank = savedata->data;
}
}
}