Make sure the saved git ver is null terminated.

strncpy() is a tricky beast.
This commit is contained in:
Unknown W. Brackets 2013-09-14 20:28:41 -07:00
parent 50e9e45d65
commit 2cca2568c7
3 changed files with 9 additions and 7 deletions

View File

@ -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<class T>
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<class T>
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) {

View File

@ -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 {

View File

@ -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"