From 467461fb3d905dd4a03932343e3fadf141813d40 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Thu, 18 Oct 2018 05:14:15 +0200 Subject: [PATCH] properly initialize shit before attempting to read from the file fixes load failure when attaching a debugger --- src/Savestate.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Savestate.cpp b/src/Savestate.cpp index fbb882be..1b6619f9 100644 --- a/src/Savestate.cpp +++ b/src/Savestate.cpp @@ -86,7 +86,7 @@ Savestate::Savestate(char* filename, bool save) len = (u32)ftell(file); fseek(file, 0, SEEK_SET); - u32 buf; + u32 buf = 0; fread(&buf, 4, 1, file); if (buf != ((u32*)magic)[0]) @@ -96,6 +96,9 @@ Savestate::Savestate(char* filename, bool save) return; } + VersionMajor = 0; + VersionMinor = 0; + fread(&VersionMajor, 2, 1, file); if (VersionMajor != SAVESTATE_MAJOR) { @@ -107,6 +110,7 @@ Savestate::Savestate(char* filename, bool save) fread(&VersionMinor, 2, 1, file); // TODO: handle it??? + buf = 0; fread(&buf, 4, 1, file); if (buf != len) { @@ -175,7 +179,7 @@ void Savestate::Section(char* magic) for (;;) { - u32 buf; + u32 buf = 0; fread(&buf, 4, 1, file); if (buf != ((u32*)magic)[0]) @@ -186,6 +190,7 @@ void Savestate::Section(char* magic) return; } + buf = 0; fread(&buf, 4, 1, file); fseek(file, buf-8, SEEK_CUR); continue;