From 2cca2568c75744628e28e762244cc0b5462987cf Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 14 Sep 2013 20:28:41 -0700 Subject: [PATCH] Make sure the saved git ver is null terminated. strncpy() is a tricky beast. --- Common/ChunkFile.h | 10 +++++----- Core/SaveState.cpp | 5 +++-- UI/CwCheatScreen.cpp | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Common/ChunkFile.h b/Common/ChunkFile.h index 8871abf75..365a51b74 100644 --- a/Common/ChunkFile.h +++ b/Common/ChunkFile.h @@ -42,7 +42,6 @@ #endif #include "Common.h" -#include "Core/Config.h" #include "FileUtil.h" #include "../ext/snappy/snappy-c.h" @@ -631,7 +630,7 @@ class CChunkFileReader public: // Load file template template - static bool Load(const std::string& _rFilename, int _Revision, T& _class, std::string* _failureReason) + static bool Load(const std::string& _rFilename, int _Revision, const char *_VersionString, T& _class, std::string* _failureReason) { INFO_LOG(COMMON, "ChunkReader: Loading %s" , _rFilename.c_str()); _failureReason->clear(); @@ -676,7 +675,7 @@ public: return false; } - if (strcmp(header.GitVersion, PPSSPP_GIT_VERSION) != 0) + if (strcmp(header.GitVersion, _VersionString) != 0) { WARN_LOG(COMMON, "This savestate was generated by a different version of PPSSPP, %s. It may not load properly.", header.GitVersion); @@ -723,7 +722,7 @@ public: // Save file template template - static bool Save(const std::string& _rFilename, int _Revision, T& _class) + static bool Save(const std::string& _rFilename, int _Revision, const char *_VersionString, T& _class) { INFO_LOG(COMMON, "ChunkReader: Writing %s" , _rFilename.c_str()); @@ -753,7 +752,8 @@ public: header.Revision = _Revision; header.ExpectedSize = (int)sz; header.UncompressedSize = (int)sz; - strncpy(header.GitVersion, PPSSPP_GIT_VERSION, 32); + strncpy(header.GitVersion, _VersionString, 32); + header.GitVersion[31] = '\0'; // Write to file if (compress) { diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 030147363..92248395f 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -21,6 +21,7 @@ #include "Common/FileUtil.h" #include "Core/SaveState.h" +#include "Core/Config.h" #include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/HLE/HLE.h" @@ -230,7 +231,7 @@ namespace SaveState if (MIPSComp::jit) MIPSComp::jit->ClearCache(); INFO_LOG(COMMON, "Loading state from %s", op.filename.c_str()); - result = CChunkFileReader::Load(op.filename, REVISION, state, &reason); + result = CChunkFileReader::Load(op.filename, REVISION, PPSSPP_GIT_VERSION, state, &reason); if (result) { osm.Show(s->T("Loaded State"), 2.0); } else { @@ -242,7 +243,7 @@ namespace SaveState if (MIPSComp::jit) MIPSComp::jit->ClearCache(); INFO_LOG(COMMON, "Saving state to %s", op.filename.c_str()); - result = CChunkFileReader::Save(op.filename, REVISION, state); + result = CChunkFileReader::Save(op.filename, REVISION, PPSSPP_GIT_VERSION, state); if (result) { osm.Show(s->T("Saved State"), 2.0); } else { diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 59d58d373..2bdeafdf8 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -23,6 +23,7 @@ #include "i18n/i18n.h" #include "Core/Core.h" +#include "Core/Config.h" #include "UI/OnScreenDisplay.h" #include "UI/ui_atlas.h"