From 080b590261a41ae487446675bfbf545fd4801728 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 2 Jun 2011 10:49:09 +0200 Subject: [PATCH] MADE: Remove all instances of s(n)printf --- engines/made/database.cpp | 6 ++---- engines/made/database.h | 2 +- engines/made/made.cpp | 4 +--- engines/made/script.cpp | 15 ++++++++------- engines/made/scriptfuncs.cpp | 16 ++++++++-------- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/engines/made/database.cpp b/engines/made/database.cpp index 6e5a3228f30..1151339d496 100644 --- a/engines/made/database.cpp +++ b/engines/made/database.cpp @@ -106,7 +106,7 @@ void Object::setVectorItem(int16 index, int16 value) { } } -void Object::dump(const char *filename) { +void Object::dump(const Common::String &filename) { /* FILE *o = fopen(filename, "wb"); fwrite(_objData, _objSize, 1, o); @@ -373,9 +373,7 @@ int16 GameDatabase::setObjectProperty(int16 objectIndex, int16 propertyId, int16 void GameDatabase::dumpObject(int16 index) { Object *obj = getObject(index); - char fn[512]; - sprintf(fn, "obj%04X.0", index); - obj->dump(fn); + obj->dump(Common::String::format("obj%04X.0", index)); } diff --git a/engines/made/database.h b/engines/made/database.h index 94acef98cd2..3bf69ca116d 100644 --- a/engines/made/database.h +++ b/engines/made/database.h @@ -62,7 +62,7 @@ public: int16 getVectorItem(int16 index); void setVectorItem(int16 index, int16 value); - void dump(const char *filename); + void dump(const Common::String &filename); protected: bool _freeData; diff --git a/engines/made/made.cpp b/engines/made/made.cpp index a9c4587b4c4..75d39fa2051 100644 --- a/engines/made/made.cpp +++ b/engines/made/made.cpp @@ -181,9 +181,7 @@ void MadeEngine::resetAllTimers() { } Common::String MadeEngine::getSavegameFilename(int16 saveNum) { - char filename[256]; - snprintf(filename, 256, "%s.%03d", getTargetName().c_str(), saveNum); - return filename; + return Common::String::format("%s.%03d", getTargetName().c_str(), saveNum); } void MadeEngine::handleEvents() { diff --git a/engines/made/script.cpp b/engines/made/script.cpp index 85e1a6ec6b3..27760088286 100644 --- a/engines/made/script.cpp +++ b/engines/made/script.cpp @@ -639,10 +639,9 @@ void ScriptInterpreter::dumpScript(int16 objectIndex, int *opcodeStats, int *ext const char *sig = _commands[opcode - 1].sig; int valueType; /* 0: dec; 1: hex; 2: extended function */ int16 value; - char tempStr[32]; opcodeStats[opcode - 1]++; - snprintf(tempStr, 32, "[%04X] ", (uint16)(code - codeStart - 1)); - codeLine += tempStr; + + codeLine += Common::String::format("[%04X] ", (uint16)(code - codeStart - 1)); codeLine += desc; for (; *sig != '\0'; sig++) { codeLine += " "; @@ -670,19 +669,21 @@ void ScriptInterpreter::dumpScript(int16 objectIndex, int *opcodeStats, int *ext value = *code++; break; } + + Common::String tempStr; switch (valueType) { case 0: - snprintf(tempStr, 32, "%d", value); + tempStr = Common::String::format("%d", value); break; case 1: - snprintf(tempStr, 32, "0x%X", value); + tempStr = Common::String::format("0x%X", value); break; case 2: if (value < _functions->getCount()) { - snprintf(tempStr, 32, "%s", _functions->getFuncName(value)); + tempStr = Common::String::format("%s", _functions->getFuncName(value)); externStats[value]++; } else { - snprintf(tempStr, 32, "invalid: %d", value); + tempStr = Common::String::format("invalid: %d", value); } break; } diff --git a/engines/made/scriptfuncs.cpp b/engines/made/scriptfuncs.cpp index 98cfb647ac1..aa172bbe74f 100644 --- a/engines/made/scriptfuncs.cpp +++ b/engines/made/scriptfuncs.cpp @@ -502,28 +502,28 @@ int16 ScriptFunctions::sfDrawText(int16 argc, int16 *argv) { } if (text) { - char finalText[1024]; + Common::String finalText; switch (argc) { case 1: - snprintf(finalText, 1024, "%s", text); + finalText = text; break; case 2: - snprintf(finalText, 1024, text, argv[0]); + finalText = Common::String::format(text, argv[0]); break; case 3: - snprintf(finalText, 1024, text, argv[1], argv[0]); + finalText = Common::String::format(text, argv[1], argv[0]); break; case 4: - snprintf(finalText, 1024, text, argv[2], argv[1], argv[0]); + finalText = Common::String::format(text, argv[2], argv[1], argv[0]); break; case 5: - snprintf(finalText, 1024, text, argv[3], argv[2], argv[1], argv[0]); + finalText = Common::String::format(text, argv[3], argv[2], argv[1], argv[0]); break; default: - finalText[0] = '\0'; + // Leave it empty break; } - _vm->_screen->printText(finalText); + _vm->_screen->printText(finalText.c_str()); } return 0;