[Scummvm-cvs-logs] SF.net SVN: scummvm:[43027] scummvm/trunk/engines/cine

buddha_ at users.sourceforge.net buddha_ at users.sourceforge.net
Mon Aug 3 19:52:07 CEST 2009


Revision: 43027
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43027&view=rev
Author:   buddha_
Date:     2009-08-03 17:52:07 +0000 (Mon, 03 Aug 2009)

Log Message:
-----------
Fix for #2824798 (FW: crash when clicking "load" in the GUI):
- Fixed CineMetaEngine::listSaves(const char *target) which was broken.
- Also added explicit initialization of savegame descriptions to
  empty strings for safety reasons (e.g. arrays on stack aren't
  initialized to zero).
- Added explicit trailing zero setting to savegame descriptions
  (Previously using GMM you could write a description of length >= 20
  that had no trailing zero when written to description file (e.g. fw.dir)).

Modified Paths:
--------------
    scummvm/trunk/engines/cine/cine.cpp
    scummvm/trunk/engines/cine/detection.cpp
    scummvm/trunk/engines/cine/saveload.cpp

Modified: scummvm/trunk/engines/cine/cine.cpp
===================================================================
--- scummvm/trunk/engines/cine/cine.cpp	2009-08-03 17:27:55 UTC (rev 43026)
+++ scummvm/trunk/engines/cine/cine.cpp	2009-08-03 17:52:07 UTC (rev 43027)
@@ -114,6 +114,9 @@
 }
 
 void CineEngine::initialize() {
+	// Initialize all savegames' descriptions to empty strings
+	memset(currentSaveName, 0, sizeof(currentSaveName));
+
 	// Resize object table to its correct size and reset all its elements
 	objectTable.resize(NUM_MAX_OBJECT);
 	resetObjectTable();

Modified: scummvm/trunk/engines/cine/detection.cpp
===================================================================
--- scummvm/trunk/engines/cine/detection.cpp	2009-08-03 17:27:55 UTC (rev 43026)
+++ scummvm/trunk/engines/cine/detection.cpp	2009-08-03 17:52:07 UTC (rev 43027)
@@ -607,35 +607,37 @@
 	pattern += ".?";
 	Common::StringList filenames = saveFileMan->listSavefiles(pattern);
 	sort(filenames.begin(), filenames.end());
-	Common::StringList::const_iterator file = filenames.begin();
+	Common::StringList::const_iterator file;
 
 	Common::String filename = target;
 	filename += ".dir";
 	Common::InSaveFile *in = saveFileMan->openForLoading(filename);
 	if (in) {
-		int8 ch;
-		char saveDesc[20];
-		do {
+		typedef char CommandeType[20];
+		CommandeType saveNames[10];
+
+		// Initialize all savegames' descriptions to empty strings
+		// so that if the savegames' descriptions can only be partially read from file
+		// then the missing ones are correctly set to empty strings.
+		memset(saveNames, 0, sizeof(saveNames));
+
+		in->read(saveNames, 10 * 20);
+		CommandeType saveDesc;
+
+		for (file = filenames.begin(); file != filenames.end(); ++file) {
+			// Jump over savegame files that don't end with a digit (e.g. "fw.3" is ok, "fw.a" is not).
+			if (!isdigit(file->lastChar()))
+				continue;
+
 			// Obtain the last digit of the filename, since they correspond to the save slot
 			int slotNum = atoi(file->c_str() + file->size() - 1);
 
-			uint pos = 0;
-			do {
-				ch = in->readByte();
-				if (pos < (sizeof(saveDesc) - 1)) {
-					if (ch < 32 || in->eos()) {
-						saveDesc[pos++] = '\0';
-					}
-					else if (ch >= 32) {
-						saveDesc[pos++] = ch;
-					}
-				}
-			} while (ch >= 32 && !in->eos());
-			if (saveDesc[0] != 0) {
-				saveList.push_back(SaveStateDescriptor(slotNum, saveDesc));
-				file++;
-			}
-		} while (!in->eos());
+			// Copy the savegame description making sure it ends with a trailing zero
+			strncpy(saveDesc, saveNames[slotNum], 20);
+			saveDesc[sizeof(CommandeType) - 1] = 0;
+
+			saveList.push_back(SaveStateDescriptor(slotNum, saveDesc));
+		}
 	}
 
 	delete in;
@@ -650,6 +652,11 @@
 	typedef char CommandeType[20];
 	CommandeType saveNames[10];
 
+	// Initialize all savegames' descriptions to empty strings
+	// so that if the savegames' descriptions can only be partially read from file
+	// then the missing ones are correctly set to empty strings.
+	memset(saveNames, 0, sizeof(saveNames));
+
 	Common::InSaveFile *in;
 	char tmp[80];
 
@@ -707,8 +714,9 @@
 	// Load savegame descriptions from index file
 	loadSaveDirectory();
 
-	// Set description for selected slot
+	// Set description for selected slot making sure it ends with a trailing zero
 	strncpy(currentSaveName[slot], desc, 20);
+	currentSaveName[slot][sizeof(CommandeType) - 1] = 0;
 
 	// Update savegame descriptions
 	char indexFile[80];

Modified: scummvm/trunk/engines/cine/saveload.cpp
===================================================================
--- scummvm/trunk/engines/cine/saveload.cpp	2009-08-03 17:27:55 UTC (rev 43026)
+++ scummvm/trunk/engines/cine/saveload.cpp	2009-08-03 17:52:07 UTC (rev 43027)
@@ -468,9 +468,18 @@
 		return false;
 	}
 
+	// Initialize all savegames' descriptions to empty strings
+	// so that if the savegames' descriptions can only be partially read from file
+	// then the missing ones are correctly set to empty strings.
+	memset(currentSaveName, 0, sizeof(currentSaveName));
+
 	fHandle->read(currentSaveName, 10 * 20);
 	delete fHandle;
 
+	// Make sure all savegames' descriptions end with a trailing zero.
+	for (int i = 0; i < ARRAYSIZE(currentSaveName); i++)
+		currentSaveName[i][sizeof(CommandeType) - 1] = 0;
+
 	return true;
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list