From 889f5d119a419b5f7f98341a8ae8d0159f9cf820 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Thu, 2 Jun 2011 02:53:48 +0100 Subject: DRASCULA: Replace snprintf() usage with Common::String::format() Safer and less portability issues. --- engines/drascula/drascula.cpp | 6 +++--- engines/drascula/drascula.h | 2 +- engines/drascula/saveload.cpp | 31 +++++++++++++++---------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/engines/drascula/drascula.cpp b/engines/drascula/drascula.cpp index cac7f93f12..b4f009eb44 100644 --- a/engines/drascula/drascula.cpp +++ b/engines/drascula/drascula.cpp @@ -893,9 +893,9 @@ bool DrasculaEngine::loadDrasculaDat() { ver = in.readByte(); if (ver != DRASCULA_DAT_VER) { - snprintf(buf, 256, "File 'drascula.dat' is wrong version. Expected %d but got %d. Get it from the ScummVM website", DRASCULA_DAT_VER, ver); - GUIErrorMessage(buf); - warning("%s", buf); + Common::String errorMessage = Common::String::format("File 'drascula.dat' is wrong version. Expected %d but got %d. Get it from the ScummVM website", DRASCULA_DAT_VER, ver); + GUIErrorMessage(errorMessage); + warning("%s", errorMessage.c_str()); return false; } diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h index f9dcbe2810..2b6aa0f291 100644 --- a/engines/drascula/drascula.h +++ b/engines/drascula/drascula.h @@ -588,7 +588,7 @@ public: void quadrant_2(); void quadrant_3(); void quadrant_4(); - void saveGame(char[]); + void saveGame(const char *gameName); void increaseFrameNum(); int whichObject(); bool checkMenuFlags(); diff --git a/engines/drascula/saveload.cpp b/engines/drascula/saveload.cpp index 15f5855bdc..664a082eb4 100644 --- a/engines/drascula/saveload.cpp +++ b/engines/drascula/saveload.cpp @@ -28,24 +28,23 @@ namespace Drascula { bool DrasculaEngine::saveLoadScreen() { char names[10][23]; - char file[50]; - char fileEpa[50]; + Common::String file; int n, n2, num_sav = 0, y = 27; Common::InSaveFile *sav; clearRoom(); - snprintf(fileEpa, 50, "%s.epa", _targetName.c_str()); + Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str()); if (!(sav = _saveFileMan->openForLoading(fileEpa))) { Common::OutSaveFile *epa; if (!(epa = _saveFileMan->openForSaving(fileEpa))) - error("Can't open %s file", fileEpa); + error("Can't open %s file", fileEpa.c_str()); for (n = 0; n < NUM_SAVES; n++) epa->writeString("*\n"); epa->finalize(); delete epa; if (!(sav = _saveFileMan->openForLoading(fileEpa))) { - error("Can't open %s file", fileEpa); + error("Can't open %s file", fileEpa.c_str()); } } for (n = 0; n < NUM_SAVES; n++) { @@ -88,11 +87,11 @@ bool DrasculaEngine::saveLoadScreen() { enterName(); strcpy(names[n], select); if (selectionMade == 1) { - snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1); - saveGame(file); + file = Common::String::format("%s%02d", _targetName.c_str(), n + 1); + saveGame(file.c_str()); Common::OutSaveFile *tsav; if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa); + error("Can't open %s file", fileEpa.c_str()); } for (n = 0; n < NUM_SAVES; n++) { tsav->writeString(names[n]); @@ -110,7 +109,7 @@ bool DrasculaEngine::saveLoadScreen() { y = y + 9; } if (selectionMade == 1) { - snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1); + file = Common::String::format("%s%02d", _targetName.c_str(), n + 1); } num_sav = n; } @@ -127,11 +126,11 @@ bool DrasculaEngine::saveLoadScreen() { } if (selectionMade == 1) { - snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1); - saveGame(file); + file = Common::String::format("%s%02d", _targetName.c_str(), n + 1); + saveGame(file.c_str()); Common::OutSaveFile *tsav; if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa); + error("Can't open %s file", fileEpa.c_str()); } for (n = 0; n < NUM_SAVES; n++) { tsav->writeString(names[n]); @@ -143,16 +142,16 @@ bool DrasculaEngine::saveLoadScreen() { } if (mouseX > 125 && mouseY > 123 && mouseX < 199 && mouseY < 149 && selectionMade == 1) { - if (!loadGame(file)) { + if (!loadGame(file.c_str())) { _system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false); return false; } break; } else if (mouseX > 208 && mouseY > 123 && mouseX < 282 && mouseY < 149 && selectionMade == 1) { - saveGame(file); + saveGame(file.c_str()); Common::OutSaveFile *tsav; if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa); + error("Can't open %s file", fileEpa.c_str()); } for (n = 0; n < NUM_SAVES; n++) { tsav->writeString(names[n]); @@ -229,7 +228,7 @@ bool DrasculaEngine::loadGame(const char *gameName) { return true; } -void DrasculaEngine::saveGame(char gameName[]) { +void DrasculaEngine::saveGame(const char *gameName) { Common::OutSaveFile *out; int l; -- cgit v1.2.3