From 8f1148498e12197745f62e477d9b8e07382cc72e Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 18 Jun 2020 01:25:48 -0700 Subject: [PATCH] GB Core: Fix extracting SRAM when none is present --- CHANGES | 1 + src/gb/core.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 006db1256..7b5f316e5 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,7 @@ Other fixes: - All: Improve export headers (fixes mgba.io/i/1738) - Core: Ensure ELF regions can be written before trying - Debugger: Don't skip undefined instructions when debugger attached + - GB Core: Fix extracting SRAM when none is present - Qt: Force OpenGL paint engine creation thread (fixes mgba.io/i/1642) - Qt: Fix static compilation in MinGW (fixes mgba.io/i/1769) Misc: diff --git a/src/gb/core.c b/src/gb/core.c index 7ee5828dd..8dee77ce3 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -822,9 +822,13 @@ static size_t _GBCoreSavedataClone(struct mCore* core, void** sram) { vf->seek(vf, 0, SEEK_SET); return vf->read(vf, *sram, vf->size(vf)); } - *sram = malloc(gb->sramSize); - memcpy(*sram, gb->memory.sram, gb->sramSize); - return gb->sramSize; + if (gb->sramSize) { + *sram = malloc(gb->sramSize); + memcpy(*sram, gb->memory.sram, gb->sramSize); + return gb->sramSize; + } + *sram = NULL; + return 0; } static bool _GBCoreSavedataRestore(struct mCore* core, const void* sram, size_t size, bool writeback) {