[Scummvm-cvs-logs] scummvm master -> c8777b774ffc4d55564503fa323b9acb986b89db

bluegr md5 at scummvm.org
Sun Sep 25 18:39:48 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c8777b774f AGI: Rewrite getSavegameFilename() so that it doesn't try to return a pointer to a local variable


Commit: c8777b774ffc4d55564503fa323b9acb986b89db
    https://github.com/scummvm/scummvm/commit/c8777b774ffc4d55564503fa323b9acb986b89db
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2011-09-25T09:33:01-07:00

Commit Message:
AGI: Rewrite getSavegameFilename() so that it doesn't try to return a pointer to a local variable

Changed paths:
    engines/agi/agi.h
    engines/agi/cycle.cpp
    engines/agi/saveload.cpp



diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 080373d..447e55e 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -881,7 +881,7 @@ public:
 
 	StringData _stringdata;
 
-	const char *getSavegameFilename(int num);
+	void getSavegameFilename(int num, char *fileName);
 	void getSavegameDescription(int num, char *buf, bool showEmpty = true);
 	int selectSlot();
 	int saveGame(const char *fileName, const char *saveName);
diff --git a/engines/agi/cycle.cpp b/engines/agi/cycle.cpp
index e6f122f..f77ef79 100644
--- a/engines/agi/cycle.cpp
+++ b/engines/agi/cycle.cpp
@@ -361,7 +361,9 @@ int AgiEngine::playGame() {
 		}
 
 		if (shouldPerformAutoSave(_lastSaveTime)) {
-			saveGame(getSavegameFilename(0), "Autosave");
+			char fileName[MAXPATHLEN];
+			getSavegameFilename(0, fileName);
+			saveGame(fileName, "Autosave");
 		}
 
 	} while (!(shouldQuit() || _restartGame));
diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp
index e62b9d4..648cb6f 100644
--- a/engines/agi/saveload.cpp
+++ b/engines/agi/saveload.cpp
@@ -546,10 +546,10 @@ int AgiEngine::loadGame(const char *fileName, bool checkId) {
 #define NUM_SLOTS 100
 #define NUM_VISIBLE_SLOTS 12
 
-const char *AgiEngine::getSavegameFilename(int num) {
+void AgiEngine::getSavegameFilename(int num, char *fileName) {
 	Common::String saveLoadSlot = _targetName;
 	saveLoadSlot += Common::String::format(".%.3d", num);
-	return saveLoadSlot.c_str();
+	strcpy(fileName, saveLoadSlot.c_str());
 }
 
 void AgiEngine::getSavegameDescription(int num, char *buf, bool showEmpty) {
@@ -557,7 +557,8 @@ void AgiEngine::getSavegameDescription(int num, char *buf, bool showEmpty) {
 	Common::InSaveFile *in;
 
 	debugC(4, kDebugLevelMain | kDebugLevelSavegame, "Current game id is %s", _targetName.c_str());
-	strcpy(fileName, getSavegameFilename(num));
+	getSavegameFilename(num, fileName);
+
 	if (!(in = _saveFileMan->openForLoading(fileName))) {
 		debugC(4, kDebugLevelMain | kDebugLevelSavegame, "File %s does not exist", fileName);
 
@@ -852,7 +853,7 @@ int AgiEngine::saveGameDialog() {
 		return errOK;
 	}
 
-	strcpy(fileName, getSavegameFilename(_firstSlot + slot));
+	getSavegameFilename(_firstSlot + slot, fileName);
 	debugC(8, kDebugLevelMain | kDebugLevelResources, "file is [%s]", fileName);
 
 	// Make sure all graphics was blitted to screen. This fixes bug
@@ -870,7 +871,10 @@ int AgiEngine::saveGameDialog() {
 }
 
 int AgiEngine::saveGameSimple() {
-	int result = saveGame(getSavegameFilename(0), "Default savegame");
+	char fileName[MAXPATHLEN];
+	getSavegameFilename(0, fileName);
+
+	int result = saveGame(fileName, "Default savegame");
 	if (result != errOK)
 		messageBox("Error saving game.");
 	return result;
@@ -904,7 +908,7 @@ int AgiEngine::loadGameDialog() {
 		return errOK;
 	}
 
-	sprintf(fileName, "%s", getSavegameFilename(_firstSlot + slot));
+	getSavegameFilename(_firstSlot + slot, fileName);
 
 	if ((rc = loadGame(fileName)) == errOK) {
 		messageBox("Game restored.");
@@ -921,7 +925,7 @@ int AgiEngine::loadGameSimple() {
 	char fileName[MAXPATHLEN];
 	int rc = 0;
 
-	sprintf(fileName, "%s", getSavegameFilename(0));
+	getSavegameFilename(0, fileName);
 
 	_sprites->eraseBoth();
 	_sound->stopSound();






More information about the Scummvm-git-logs mailing list