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