Updated state.cpp so that .luasav file paths use std::string so that they aren't limited in size.

This commit is contained in:
harry 2023-01-31 00:27:01 -05:00
parent 5ed3463c01
commit 4a54f43246
1 changed files with 9 additions and 11 deletions

View File

@ -511,13 +511,12 @@ void FCEUSS_Save(const char *fname, bool display_message)
LuaSaveData saveData; LuaSaveData saveData;
CallRegisteredLuaSaveFunctions(CurrentState, saveData); CallRegisteredLuaSaveFunctions(CurrentState, saveData);
char luaSaveFilename [512]; std::string luaSaveFilename;
strncpy(luaSaveFilename, fn.c_str(), 512); luaSaveFilename.assign(fn.c_str());
luaSaveFilename[512-(1+7/*strlen(".luasav")*/)] = '\0'; luaSaveFilename.append(".luasav");
strcat(luaSaveFilename, ".luasav");
if(saveData.recordList) if(saveData.recordList)
{ {
FILE* luaSaveFile = fopen(luaSaveFilename, "wb"); FILE* luaSaveFile = fopen(luaSaveFilename.c_str(), "wb");
if(luaSaveFile) if(luaSaveFile)
{ {
saveData.ExportRecords(luaSaveFile); saveData.ExportRecords(luaSaveFile);
@ -526,7 +525,7 @@ void FCEUSS_Save(const char *fname, bool display_message)
} }
else else
{ {
unlink(luaSaveFilename); unlink(luaSaveFilename.c_str());
} }
} }
#endif #endif
@ -792,11 +791,10 @@ bool FCEUSS_Load(const char *fname, bool display_message)
{ {
LuaSaveData saveData; LuaSaveData saveData;
char luaSaveFilename [512]; std::string luaSaveFilename;
strncpy(luaSaveFilename, fn.c_str(), 512); luaSaveFilename.assign(fn.c_str());
luaSaveFilename[512-(1+7/*strlen(".luasav")*/)] = '\0'; luaSaveFilename.append(".luasav");
strcat(luaSaveFilename, ".luasav"); FILE* luaSaveFile = fopen(luaSaveFilename.c_str(), "rb");
FILE* luaSaveFile = fopen(luaSaveFilename, "rb");
if(luaSaveFile) if(luaSaveFile)
{ {
saveData.ImportRecords(luaSaveFile); saveData.ImportRecords(luaSaveFile);