[Scummvm-cvs-logs] SF.net SVN: scummvm: [27485] scummvm/branches/branch-0-10-0/engines/sword1/ control.cpp

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Sat Jun 16 21:29:15 CEST 2007


Revision: 27485
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27485&view=rev
Author:   eriktorbjorn
Date:     2007-06-16 12:29:14 -0700 (Sat, 16 Jun 2007)

Log Message:
-----------
Backported rubustness changes when reading SAVEGAME.INF. We shouldn't have to
do this, of course, but since a mutilated SAVEGAME.INF could cause you to lose
the ability to load any of your savegames, it's not completely unwarranted...

Sometimes, I really dislike engines using this kind of "index" file for their
savegames...

Modified Paths:
--------------
    scummvm/branches/branch-0-10-0/engines/sword1/control.cpp

Modified: scummvm/branches/branch-0-10-0/engines/sword1/control.cpp
===================================================================
--- scummvm/branches/branch-0-10-0/engines/sword1/control.cpp	2007-06-16 19:27:05 UTC (rev 27484)
+++ scummvm/branches/branch-0-10-0/engines/sword1/control.cpp	2007-06-16 19:29:14 UTC (rev 27485)
@@ -700,6 +700,9 @@
 	inf = _saveFileMan->openForLoading("SAVEGAME.INF");
 	_saveScrollPos = _saveFiles = 0;
 	_selectedSavegame = 255;
+	for (uint8 cnt = 0; cnt < 64; cnt++) {
+		memset(_saveNames[cnt], 0, sizeof(_saveNames[cnt]));
+	}
 	if (inf) {
 		uint8 curFileNum = 0;
 		uint8 ch;
@@ -707,20 +710,18 @@
 			uint8 pos = 0;
 			do {
 				ch = inf->readByte();
-				if ((ch == 10) || (ch == 255))
-					_saveNames[curFileNum][pos] = '\0';
-				else
-					_saveNames[curFileNum][pos] = ch;
-				pos++;
-			} while ((ch != 10) && (ch != 255));
-			curFileNum++;
-		} while (ch != 255);
+				if (pos < sizeof(_saveNames[curFileNum]) - 1) {
+					if ((ch == 10) || (ch == 255) || (inf->eos()))
+						_saveNames[curFileNum][pos++] = '\0';
+					else if (ch >= 32)
+						_saveNames[curFileNum][pos++] = ch;
+				}
+			} while ((ch != 10) && (ch != 255) && (!inf->eos()));
+			if (_saveNames[curFileNum][0] != 0)
+				curFileNum++;
+		} while ((ch != 255) && (!inf->eos()));
 		_saveFiles = curFileNum;
-		for (uint8 cnt = _saveFiles; cnt < 64; cnt++)
-			_saveNames[cnt][0] = '\0';
-	} else
-		for (uint8 cnt = 0; cnt < 64; cnt++)
-			_saveNames[cnt][0] = '\0';
+	}
 	delete inf;
 }
 


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