all repos — mgba @ b0a2df6190a37fcc112f6599ccf021c49d11ed6c

mGBA Game Boy Advance Emulator

GB MBC: Fix RTC loading when file size is off
Vicki Pfau vi@endrift.com
Sat, 29 Jul 2017 22:48:37 -0700
commit

b0a2df6190a37fcc112f6599ccf021c49d11ed6c

parent

defc263711529cdd4d58b74c53d33f3b677ecca6

2 files changed, 4 insertions(+), 10 deletions(-)

jump to
M CHANGESCHANGES

@@ -12,6 +12,7 @@ - Qt: Fix LOG argument order

- GB Memory: Prevent accessing empty SRAM (fixes mgba.io/i/831) - GB, GBA: Fix crashes when attempting to identify null VFiles - GB MBC: Fix RTC initialization (fixes mgba.io/i/825) + - GB MBC: Fix RTC loading when file size is off Misc: - Qt: Don't rebuild library view if style hasn't changed - SDL: Fix 2.0.5 build on macOS under some circumstances
M src/gb/mbc.csrc/gb/mbc.c

@@ -768,17 +768,10 @@ struct VFile* vf = gb->sramVf;

if (!vf) { return; } - ssize_t end = vf->seek(vf, -sizeof(rtcBuffer), SEEK_END); - switch (end & 0x1FFF) { - case 0: - break; - case 0x1FFC: - vf->seek(vf, -sizeof(rtcBuffer) - 4, SEEK_END); - break; - default: + vf->seek(vf, gb->sramSize, SEEK_SET); + if (vf->read(vf, &rtcBuffer, sizeof(rtcBuffer)) < (ssize_t) sizeof(rtcBuffer) - 4) { return; } - vf->read(vf, &rtcBuffer, sizeof(rtcBuffer)); LOAD_32LE(gb->memory.rtcRegs[0], 0, &rtcBuffer.latchedSec); LOAD_32LE(gb->memory.rtcRegs[1], 0, &rtcBuffer.latchedMin);

@@ -812,7 +805,7 @@ STORE_32LE(gb->memory.rtcRegs[3], 0, &rtcBuffer.latchedDays);

STORE_32LE(gb->memory.rtcRegs[4], 0, &rtcBuffer.latchedDaysHi); STORE_64LE(gb->memory.rtcLastLatch, 0, &rtcBuffer.unixTime); - if (vf->size(vf) == gb->sramSize) { + if ((size_t) vf->size(vf) < gb->sramSize + sizeof(rtcBuffer)) { // Writing past the end of the file can invalidate the file mapping vf->unmap(vf, gb->memory.sram, gb->sramSize); gb->memory.sram = NULL;