GB: Fix crash when patching ROM

This commit is contained in:
Vicki Pfau 2017-02-01 13:47:03 -08:00
parent 9959ef8570
commit 6df55275b8
2 changed files with 5 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Bugfixes:
- Qt: Fix timing issues on high refresh rate monitors - Qt: Fix timing issues on high refresh rate monitors
- GBA Savedata: Fix savedata unmasking (fixes mgba.io/i/441) - GBA Savedata: Fix savedata unmasking (fixes mgba.io/i/441)
- Util: Fix overflow when loading invalid UPS patches - Util: Fix overflow when loading invalid UPS patches
- GB: Fix crash when patching ROMs
Misc: Misc:
- Qt: Improved HiDPI support - Qt: Improved HiDPI support
- Feature: Support ImageMagick 7 - Feature: Support ImageMagick 7

View File

@ -285,12 +285,16 @@ void GBApplyPatch(struct GB* gb, struct Patch* patch) {
if (patchedSize > GB_SIZE_CART_MAX) { if (patchedSize > GB_SIZE_CART_MAX) {
patchedSize = GB_SIZE_CART_MAX; patchedSize = GB_SIZE_CART_MAX;
} }
void* oldRom = gb->memory.rom;
gb->memory.rom = anonymousMemoryMap(GB_SIZE_CART_MAX); gb->memory.rom = anonymousMemoryMap(GB_SIZE_CART_MAX);
if (!patch->applyPatch(patch, gb->pristineRom, gb->pristineRomSize, gb->memory.rom, patchedSize)) { if (!patch->applyPatch(patch, gb->pristineRom, gb->pristineRomSize, gb->memory.rom, patchedSize)) {
mappedMemoryFree(gb->memory.rom, patchedSize); mappedMemoryFree(gb->memory.rom, patchedSize);
gb->memory.rom = gb->pristineRom; gb->memory.rom = gb->pristineRom;
return; return;
} }
if (gb->memory.romBase == oldRom) {
gb->memory.romBase = gb->memory.rom;
}
gb->memory.romSize = patchedSize; gb->memory.romSize = patchedSize;
gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize); gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize);
} }