From ecc3c3a81619e58776f765c5e53b964e4d709825 Mon Sep 17 00:00:00 2001 From: Daniel Wong Date: Wed, 21 Jul 2021 22:35:55 +1000 Subject: [PATCH] Fix unable to save/load issue (on Steam exe only) - This issue was caused by the lack of a null terminator when reading the save location from the saveloc.txt file, resulting in the game attempting to read a path with some junk at the end - Previously, only the first element of the array was initialized. Any bytes not overwritten by fread(...) would remain uninitialized. - I also modified fread to read 511 instead of 512 bytes, so that there will always be a null terminator, even if fread reads the full 511 bytes. --- src/PonscripterLabel.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PonscripterLabel.cpp b/src/PonscripterLabel.cpp index fbe77058..7eef75e1 100644 --- a/src/PonscripterLabel.cpp +++ b/src/PonscripterLabel.cpp @@ -883,11 +883,10 @@ pstring Steam_GetSavePath(const pstring& local_savedir) { pstring saveloc = savedirdir + "saveloc.txt"; FILE* savelocfile = fopen(saveloc, "r"); - char path[512]; + char path[512] = { 0 }; pstring savelocContent; - path[0] = 0; if (savelocfile) { - while (fread(path, 1, sizeof(path), savelocfile)) { + while (fread(path, 1, sizeof(path)-1, savelocfile)) { savelocContent += path; } fclose(savelocfile);