all repos — mgba @ a8192f47e2ae22d244835ecf433aaeec003d340c

mGBA Game Boy Advance Emulator

GBA: Better memory handling with PNG savestates
Jeffrey Pfau jeffrey@endrift.com
Sun, 30 Aug 2015 19:14:59 -0700
commit

a8192f47e2ae22d244835ecf433aaeec003d340c

parent

34fd6769e6fdf27a4394783a8d57135bee25af1e

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

jump to
M CHANGESCHANGES

@@ -14,6 +14,7 @@ - Qt: Remove useless help icons in dialogs

- ARM7: Combine shifter-immediate and shifter-register functions to reduce binary size - SDL: Support fullscreen in SDL 1.2 - GBA: Attempting to save a screenshot-style savestate should be allowed without libpng + - GBA: Better memory handling with PNG savestates 0.3.0: (2015-08-16) Features:
M src/gba/serialize.csrc/gba/serialize.c

@@ -234,12 +234,14 @@ static int _loadPNGChunkHandler(png_structp png, png_unknown_chunkp chunk) {

if (strcmp((const char*) chunk->name, "gbAs") != 0) { return 0; } - struct GBASerializedState state; - uLongf len = sizeof(state); - uncompress((Bytef*) &state, &len, chunk->data, chunk->size); - if (!GBADeserialize(png_get_user_chunk_ptr(png), &state)) { + struct GBASerializedState* state = malloc(sizeof(*state)); + uLongf len = sizeof(*state); + uncompress((Bytef*) state, &len, chunk->data, chunk->size); + if (!GBADeserialize(png_get_user_chunk_ptr(png), state)) { + free(state); longjmp(png_jmpbuf(png), 1); } + free(state); return 1; }

@@ -252,6 +254,10 @@ PNGReadClose(png, info, end);

return false; } uint32_t* pixels = malloc(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); + if (!pixels) { + PNGReadClose(png, info, end); + return false; + } PNGInstallChunkHandler(png, gba, _loadPNGChunkHandler, "gbAs"); bool success = PNGReadHeader(png, info);