[Scummvm-cvs-logs] scummvm master -> 24ac81ead8b5bcee8ee7ded4f7b1ed7f2f263e65

digitall digitall at scummvm.org
Thu Jun 2 05:23:50 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:
24ac81ead8 SWORD1: Replace snprintf() usage with Common::String::format()


Commit: 24ac81ead8b5bcee8ee7ded4f7b1ed7f2f263e65
    https://github.com/scummvm/scummvm/commit/24ac81ead8b5bcee8ee7ded4f7b1ed7f2f263e65
Author: D G Turner (digitall at scummvm.org)
Date: 2011-06-01T20:21:48-07:00

Commit Message:
SWORD1: Replace snprintf() usage with Common::String::format()

Safer and less portability issues.

Changed paths:
    engines/sword1/animation.cpp
    engines/sword1/detection.cpp



diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp
index b66cc6b..7e9d114 100644
--- a/engines/sword1/animation.cpp
+++ b/engines/sword1/animation.cpp
@@ -85,7 +85,7 @@ MoviePlayer::~MoviePlayer() {
  */
 bool MoviePlayer::load(uint32 id) {
 	Common::File f;
-	char filename[20];
+	Common::String filename;
 
 	if (_decoderType == kVideoDecoderDXA)
 		_bgSoundStream = Audio::SeekableAudioStream::openStreamFile(sequenceList[id]);
@@ -93,7 +93,7 @@ bool MoviePlayer::load(uint32 id) {
 		_bgSoundStream = NULL;
 
 	if (SwordEngine::_systemVars.showText) {
-		sprintf(filename, "%s.txt", sequenceList[id]);
+		filename = Common::String::format("%s.txt", sequenceList[id]);
 		if (f.open(filename)) {
 			Common::String line;
 			int lineNo = 0;
@@ -117,12 +117,12 @@ bool MoviePlayer::load(uint32 id) {
 					ptr++;
 
 				if (startFrame > endFrame) {
-					warning("%s:%d: startFrame (%d) > endFrame (%d)", filename, lineNo, startFrame, endFrame);
+					warning("%s:%d: startFrame (%d) > endFrame (%d)", filename.c_str(), lineNo, startFrame, endFrame);
 					continue;
 				}
 
 				if (startFrame <= lastEnd) {
-					warning("%s:%d startFrame (%d) <= lastEnd (%d)", filename, lineNo, startFrame, lastEnd);
+					warning("%s:%d startFrame (%d) <= lastEnd (%d)", filename.c_str(), lineNo, startFrame, lastEnd);
 					continue;
 				}
 
@@ -135,14 +135,14 @@ bool MoviePlayer::load(uint32 id) {
 
 	switch (_decoderType) {
 	case kVideoDecoderDXA:
-		snprintf(filename, sizeof(filename), "%s.dxa", sequenceList[id]);
+		filename = Common::String::format("%s.dxa", sequenceList[id]);
 		break;
 	case kVideoDecoderSMK:
-		snprintf(filename, sizeof(filename), "%s.smk", sequenceList[id]);
+		filename = Common::String::format("%s.smk", sequenceList[id]);
 		break;
 	}
 
-	return _decoder->loadFile(filename);
+	return _decoder->loadFile(filename.c_str());
 }
 
 void MoviePlayer::play() {
@@ -323,18 +323,18 @@ uint32 DXADecoderWithSound::getElapsedTime() const {
 ///////////////////////////////////////////////////////////////////////////////
 
 MoviePlayer *makeMoviePlayer(uint32 id, SwordEngine *vm, Text *textMan, Audio::Mixer *snd, OSystem *system) {
-	char filename[20];
+	Common::String filename;
 	char buf[60];
 	Audio::SoundHandle *bgSoundHandle = new Audio::SoundHandle;
 
-	snprintf(filename, sizeof(filename), "%s.smk", sequenceList[id]);
+	filename = Common::String::format("%s.smk", sequenceList[id]);
 
 	if (Common::File::exists(filename)) {
 		Video::SmackerDecoder *smkDecoder = new Video::SmackerDecoder(snd);
 		return new MoviePlayer(vm, textMan, snd, system, bgSoundHandle, smkDecoder, kVideoDecoderSMK);
 	}
 
-	snprintf(filename, sizeof(filename), "%s.dxa", sequenceList[id]);
+	filename = Common::String::format("%s.dxa", sequenceList[id]);
 
 	if (Common::File::exists(filename)) {
 #ifdef USE_ZLIB
@@ -348,7 +348,7 @@ MoviePlayer *makeMoviePlayer(uint32 id, SwordEngine *vm, Text *textMan, Audio::M
 	}
 
 	// Old MPEG2 cutscenes
-	snprintf(filename, sizeof(filename), "%s.mp2", sequenceList[id]);
+	filename = Common::String::format("%s.mp2", sequenceList[id]);
 
 	if (Common::File::exists(filename)) {
 		GUI::MessageDialog dialog("MPEG2 cutscenes are no longer supported", "OK");
diff --git a/engines/sword1/detection.cpp b/engines/sword1/detection.cpp
index 8ffd96d..b02cadc 100644
--- a/engines/sword1/detection.cpp
+++ b/engines/sword1/detection.cpp
@@ -249,15 +249,11 @@ SaveStateList SwordMetaEngine::listSaves(const char *target) const {
 int SwordMetaEngine::getMaximumSaveSlot() const { return 999; }
 
 void SwordMetaEngine::removeSaveState(const char *target, int slot) const {
-	char fileName[12];
-	snprintf(fileName, 12, "sword1.%03d", slot);
-
-	g_system->getSavefileManager()->removeSavefile(fileName);
+	g_system->getSavefileManager()->removeSavefile(Common::String::format("sword1.%03d", slot));
 }
 
 SaveStateDescriptor SwordMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
-	char fileName[12];
-	snprintf(fileName, 12, "sword1.%03d", slot);
+	Common::String fileName = Common::String::format("sword1.%03d", slot);
 	char name[40];
 	uint32 playTime = 0;
 	byte versionSave;






More information about the Scummvm-git-logs mailing list