SCUMM: Don't use unsafe sprintf and vsprintf

This commit is contained in:
Le Philousophe 2022-10-23 15:26:54 +02:00 committed by Eugene Sandulenko
parent f54bdf989a
commit 137b51d7ac
16 changed files with 35 additions and 35 deletions

View file

@ -2072,7 +2072,7 @@ void CharsetRendererNut::setCurID(int32 id) {
_curId = id; _curId = id;
if (!_fr[id]) { if (!_fr[id]) {
char fontname[11]; char fontname[11];
sprintf(fontname, "font%d.nut", id); Common::sprintf_s(fontname, "font%d.nut", id);
_fr[id] = new NutRenderer(_vm, fontname); _fr[id] = new NutRenderer(_vm, fontname);
} }
_current = _fr[id]; _current = _fr[id];

View file

@ -349,13 +349,13 @@ void ScummEngine_v72he::decodeScriptString(byte *dst, bool scriptString) {
chr = string[num++]; chr = string[num++];
switch (chr) { switch (chr) {
case 'b': case 'b':
//dst += sprintf((char *)dst, "%b", args[val++]); //dst += Common::sprintf_s((char *)dst, "%b", args[val++]);
break; break;
case 'c': case 'c':
*dst++ = args[val++]; *dst++ = args[val++];
break; break;
case 'd': case 'd':
dst += sprintf((char *)dst, "%d", args[val++]); dst += Common::sprintf_s((char *)dst, sizeof(string) - (dst - dst0), "%d", args[val++]);
break; break;
case 's': case 's':
src = getStringAddress(args[val++]); src = getStringAddress(args[val++]);
@ -365,7 +365,7 @@ void ScummEngine_v72he::decodeScriptString(byte *dst, bool scriptString) {
} }
break; break;
case 'x': case 'x':
dst += sprintf((char *)dst, "%x", args[val++]); dst += Common::sprintf_s((char *)dst, sizeof(string) - (dst - dst0), "%x", args[val++]);
break; break;
default: default:
*dst++ = '%'; *dst++ = '%';

View file

@ -216,7 +216,7 @@ void ScummEngine_v80he::o80_writeConfigFile() {
case 43: // HE 100 case 43: // HE 100
case 6: // number case 6: // number
value = pop(); value = pop();
sprintf((char *)string, "%d", value); Common::sprintf_s(string, "%d", value);
copyScriptString(option, sizeof(option)); copyScriptString(option, sizeof(option));
copyScriptString(section, sizeof(section)); copyScriptString(section, sizeof(section));
copyScriptString(filename, sizeof(filename)); copyScriptString(filename, sizeof(filename));

View file

@ -81,7 +81,7 @@ bool ImuseDigiSndMgr::openMusicBundle(SoundDesc *sound, int &disk) {
char musicfile[20]; char musicfile[20];
if (disk == -1) if (disk == -1)
disk = _vm->VAR(_vm->VAR_CURRENTDISK); disk = _vm->VAR(_vm->VAR_CURRENTDISK);
sprintf(musicfile, "musdisk%d.bun", disk); Common::sprintf_s(musicfile, "musdisk%d.bun", disk);
// if (_disk != _vm->VAR(_vm->VAR_CURRENTDISK)) { // if (_disk != _vm->VAR(_vm->VAR_CURRENTDISK)) {
// _vm->_DiMUSE_v1->parseScriptCmds(0x1000, 0, 0, 0, 0, 0, 0, 0); // _vm->_DiMUSE_v1->parseScriptCmds(0x1000, 0, 0, 0, 0, 0, 0, 0);
// _vm->_DiMUSE_v1->parseScriptCmds(0x2000, 0, 0, 0, 0, 0, 0, 0); // _vm->_DiMUSE_v1->parseScriptCmds(0x2000, 0, 0, 0, 0, 0, 0, 0);
@ -117,7 +117,7 @@ bool ImuseDigiSndMgr::openVoiceBundle(SoundDesc *sound, int &disk) {
char voxfile[20]; char voxfile[20];
if (disk == -1) if (disk == -1)
disk = _vm->VAR(_vm->VAR_CURRENTDISK); disk = _vm->VAR(_vm->VAR_CURRENTDISK);
sprintf(voxfile, "voxdisk%d.bun", disk); Common::sprintf_s(voxfile, "voxdisk%d.bun", disk);
// if (_disk != _vm->VAR(_vm->VAR_CURRENTDISK)) { // if (_disk != _vm->VAR(_vm->VAR_CURRENTDISK)) {
// _vm->_DiMUSE_v1->parseScriptCmds(0x1000, 0, 0, 0, 0, 0, 0, 0); // _vm->_DiMUSE_v1->parseScriptCmds(0x1000, 0, 0, 0, 0, 0, 0, 0);
// _vm->_DiMUSE_v1->parseScriptCmds(0x2000, 0, 0, 0, 0, 0, 0, 0); // _vm->_DiMUSE_v1->parseScriptCmds(0x2000, 0, 0, 0, 0, 0, 0, 0);

View file

@ -831,7 +831,7 @@ void ScummEngine_v3::processKeyboard(Common::KeyState lastKeyHit) {
updateIQPoints(); updateIQPoints();
sprintf(text, "IQ Points: Episode = %d, Series = %d", _scummVars[244], _scummVars[245]); Common::sprintf_s(text, "IQ Points: Episode = %d, Series = %d", _scummVars[244], _scummVars[245]);
Indy3IQPointsDialog indy3IQPointsDialog(this, text); Indy3IQPointsDialog indy3IQPointsDialog(this, text);
runDialog(indy3IQPointsDialog); runDialog(indy3IQPointsDialog);
} }

View file

@ -1055,17 +1055,17 @@ void Insane::postCase16(byte *renderBitmap, int32 codecparam, int32 setupsan12,
int32 tmp; int32 tmp;
turnBen(true); turnBen(true);
sprintf(buf, "^f01%02o", curFrame & 0x3f); Common::sprintf_s(buf, "^f01%02o", curFrame & 0x3f);
smlayer_showStatusMsg(-1, renderBitmap, codecparam, 180, 168, 1, 2, 0, "%s", buf); smlayer_showStatusMsg(-1, renderBitmap, codecparam, 180, 168, 1, 2, 0, "%s", buf);
tmp = 400-curFrame; tmp = 400-curFrame;
if (tmp < 0) if (tmp < 0)
tmp += 1300; tmp += 1300;
sprintf(buf, "^f01%04d", tmp); Common::sprintf_s(buf, "^f01%04d", tmp);
smlayer_showStatusMsg(-1, renderBitmap, codecparam, 202, 168, 1, 2, 0, "%s", buf); smlayer_showStatusMsg(-1, renderBitmap, codecparam, 202, 168, 1, 2, 0, "%s", buf);
sprintf(buf, "^f01%02o", curFrame & 0xff); Common::sprintf_s(buf, "^f01%02o", curFrame & 0xff);
smlayer_showStatusMsg(-1, renderBitmap, codecparam, 240, 168, 1, 2, 0, "%s", buf); smlayer_showStatusMsg(-1, renderBitmap, codecparam, 240, 168, 1, 2, 0, "%s", buf);
smlayer_showStatusMsg(-1, renderBitmap, codecparam, 170, 43, 1, 2, 0, "%s", buf); smlayer_showStatusMsg(-1, renderBitmap, codecparam, 170, 43, 1, 2, 0, "%s", buf);

View file

@ -863,7 +863,7 @@ void ScummEngine::resetRoomObjects() {
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
sprintf(buf, "roomobj-%d-", _roomResource); Common::sprintf_s(buf, "roomobj-%d-", _roomResource);
ptr = findResource(MKTAG('V','E','R','B'), ptr); ptr = findResource(MKTAG('V','E','R','B'), ptr);
dumpResource(buf, od->obj_nr, ptr); dumpResource(buf, od->obj_nr, ptr);
} }
@ -928,7 +928,7 @@ void ScummEngine_v3old::resetRoomObjects() {
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
sprintf(buf, "roomobj-%d-", _roomResource); Common::sprintf_s(buf, "roomobj-%d-", _roomResource);
dumpResource(buf, od->obj_nr, room + od->OBCDoffset); dumpResource(buf, od->obj_nr, room + od->OBCDoffset);
} }
} }
@ -962,7 +962,7 @@ void ScummEngine_v4::resetRoomObjects() {
od->obj_nr = READ_LE_UINT16(ptr + 6); od->obj_nr = READ_LE_UINT16(ptr + 6);
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
sprintf(buf, "roomobj-%d-", _roomResource); Common::sprintf_s(buf, "roomobj-%d-", _roomResource);
dumpResource(buf, od->obj_nr, ptr); dumpResource(buf, od->obj_nr, ptr);
} }
} }
@ -1981,7 +1981,7 @@ void ScummEngine::loadFlObject(uint object, uint room) {
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
const byte *ptr = foir.obcd; const byte *ptr = foir.obcd;
sprintf(buf, "roomobj-%u-", room); Common::sprintf_s(buf, "roomobj-%u-", room);
ptr = findResource(MKTAG('V','E','R','B'), ptr); ptr = findResource(MKTAG('V','E','R','B'), ptr);
dumpResource(buf, object, ptr); dumpResource(buf, object, ptr);
} }

View file

@ -221,9 +221,9 @@ void ScummEngine::askForDisk(const char *filename, int disknum) {
_imuseDigital->stopAllSounds(); _imuseDigital->stopAllSounds();
#ifdef MACOSX #ifdef MACOSX
sprintf(buf, "Cannot find file: '%s'\nPlease insert disc %d.\nPress OK to retry, Quit to exit", filename, disknum); Common::sprintf_s(buf, "Cannot find file: '%s'\nPlease insert disc %d.\nPress OK to retry, Quit to exit", filename, disknum);
#else #else
sprintf(buf, "Cannot find file: '%s'\nInsert disc %d into drive %s\nPress OK to retry, Quit to exit", filename, disknum, ConfMan.get("path").c_str()); Common::sprintf_s(buf, "Cannot find file: '%s'\nInsert disc %d into drive %s\nPress OK to retry, Quit to exit", filename, disknum, ConfMan.get("path").c_str());
#endif #endif
result = displayMessage("Quit", "%s", buf); result = displayMessage("Quit", "%s", buf);
@ -232,7 +232,7 @@ void ScummEngine::askForDisk(const char *filename, int disknum) {
} }
#endif #endif
} else { } else {
sprintf(buf, "Cannot find file: '%s'", filename); Common::sprintf_s(buf, "Cannot find file: '%s'", filename);
InfoDialog dialog(this, Common::U32String(buf)); InfoDialog dialog(this, Common::U32String(buf));
runDialog(dialog); runDialog(dialog);
error("Cannot find file: '%s'", filename); error("Cannot find file: '%s'", filename);
@ -1445,7 +1445,7 @@ void ScummEngine::dumpResource(const char *tag, int id, const byte *ptr, int len
else else
size = READ_BE_UINT32(ptr + 4); size = READ_BE_UINT32(ptr + 4);
sprintf(buf, "dumps/%s%d.dmp", tag, id); Common::sprintf_s(buf, "dumps/%s%d.dmp", tag, id);
out.open(buf); out.open(buf);
if (out.isOpen() == false) if (out.isOpen() == false)
@ -1662,7 +1662,7 @@ const char *nameOfResType(ResType type) {
case rtSpoolBuffer: case rtSpoolBuffer:
return "SpoolBuffer"; return "SpoolBuffer";
default: default:
sprintf(buf, "rt%d", type); Common::sprintf_s(buf, "rt%d", type);
return buf; return buf;
} }
} }

View file

@ -108,7 +108,7 @@ void ScummEngine_v3::loadCharset(int no) {
Common::File file; Common::File file;
char buf[20]; char buf[20];
sprintf(buf, "%02d.LFL", 99 - no); Common::sprintf_s(buf, "%02d.LFL", 99 - no);
file.open(buf); file.open(buf);
if (file.isOpen() == false) { if (file.isOpen() == false) {

View file

@ -163,7 +163,7 @@ void ScummEngine_v4::loadCharset(int no) {
char buf[20]; char buf[20];
byte *data; byte *data;
sprintf(buf, "%03d.LFL", 900 + no); Common::sprintf_s(buf, "%03d.LFL", 900 + no);
file.open(buf); file.open(buf);
if (file.isOpen() == false) { if (file.isOpen() == false) {

View file

@ -360,7 +360,7 @@ void ScummEngine::setupRoomSubBlocks() {
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
sprintf(buf, "room-%d-", _roomResource); Common::sprintf_s(buf, "room-%d-", _roomResource);
dumpResource(buf, id, ptr - _resourceHeaderSize); dumpResource(buf, id, ptr - _resourceHeaderSize);
} }
@ -380,7 +380,7 @@ void ScummEngine::setupRoomSubBlocks() {
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
sprintf(buf, "room-%d-", _roomResource); Common::sprintf_s(buf, "room-%d-", _roomResource);
dumpResource(buf, id, ptr - _resourceHeaderSize); dumpResource(buf, id, ptr - _resourceHeaderSize);
} }
} }
@ -396,7 +396,7 @@ void ScummEngine::setupRoomSubBlocks() {
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
sprintf(buf, "room-%d-", _roomResource); Common::sprintf_s(buf, "room-%d-", _roomResource);
dumpResource(buf, id, ptr - _resourceHeaderSize); dumpResource(buf, id, ptr - _resourceHeaderSize);
} }
} }
@ -423,7 +423,7 @@ void ScummEngine::setupRoomSubBlocks() {
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
sprintf(buf, "room-%d-", _roomResource); Common::sprintf_s(buf, "room-%d-", _roomResource);
dumpResource(buf, id, ptr - _resourceHeaderSize); dumpResource(buf, id, ptr - _resourceHeaderSize);
} }
} }
@ -733,7 +733,7 @@ void ScummEngine_v3old::setupRoomSubBlocks() {
if (_dumpScripts) { if (_dumpScripts) {
char buf[32]; char buf[32];
sprintf(buf, "room-%d-", _roomResource); Common::sprintf_s(buf, "room-%d-", _roomResource);
// HACK: to determine the sizes of the local scripts, we assume that // HACK: to determine the sizes of the local scripts, we assume that
// a) their order in the data file is the same as in the index // a) their order in the data file is the same as in the index

View file

@ -1431,8 +1431,8 @@ void ScummEngine::saveLoadWithSerializer(Common::Serializer &s) {
if (s.isLoading()) { if (s.isLoading()) {
char md5str1[32+1], md5str2[32+1]; char md5str1[32+1], md5str2[32+1];
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
sprintf(md5str1 + i*2, "%02x", (int)_gameMD5[i]); Common::sprintf_s(md5str1 + i*2, 3, "%02x", (int)_gameMD5[i]);
sprintf(md5str2 + i*2, "%02x", (int)md5Backup[i]); Common::sprintf_s(md5str2 + i*2, 3, "%02x", (int)md5Backup[i]);
} }
debug(2, "Save version: %d", s.getVersion()); debug(2, "Save version: %d", s.getVersion());

View file

@ -418,7 +418,7 @@ void ScummEngine_v4::o4_saveLoadGame() {
char name[32]; char name[32];
if (_game.version <= 2) { if (_game.version <= 2) {
// use generic name // use generic name
sprintf(name, "Game %c", 'A'+slot-1); Common::sprintf_s(name, "Game %c", 'A'+slot-1);
} else { } else {
// use name entered by the user // use name entered by the user
char* ptr; char* ptr;

View file

@ -982,7 +982,7 @@ SmushFont *SmushPlayer::getFont(int font) {
} else { } else {
int numFonts = (_vm->_game.id == GID_CMI && !(_vm->_game.features & GF_DEMO)) ? 5 : 4; int numFonts = (_vm->_game.id == GID_CMI && !(_vm->_game.features & GF_DEMO)) ? 5 : 4;
assert(font >= 0 && font < numFonts); assert(font >= 0 && font < numFonts);
sprintf(file_font, "font%d.nut", font); Common::sprintf_s(file_font, "font%d.nut", font);
_sf[font] = new SmushFont(_vm, file_font, _vm->_game.id == GID_DIG && font != 0); _sf[font] = new SmushFont(_vm, file_font, _vm->_game.id == GID_DIG && font != 0);
} }

View file

@ -752,14 +752,14 @@ void Sound::startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle
if (!file) if (!file)
error("startTalkSound: Out of memory"); error("startTalkSound: Out of memory");
sprintf(filename, "audio/%s.%u/%u.voc", roomname, offset, b); Common::sprintf_s(filename, "audio/%s.%u/%u.voc", roomname, offset, b);
if (!_vm->openFile(*file, filename)) { if (!_vm->openFile(*file, filename)) {
sprintf(filename, "audio/%s_%u/%u.voc", roomname, offset, b); Common::sprintf_s(filename, "audio/%s_%u/%u.voc", roomname, offset, b);
_vm->openFile(*file, filename); _vm->openFile(*file, filename);
} }
if (!file->isOpen()) { if (!file->isOpen()) {
sprintf(filename, "%u.%u.voc", offset, b); Common::sprintf_s(filename, "%u.%u.voc", offset, b);
_vm->openFile(*file, filename); _vm->openFile(*file, filename);
} }

View file

@ -1656,7 +1656,7 @@ void ScummEngine_v7::loadLanguageBundle() {
} }
// The tag is the basetag, followed by a dot and then the index // The tag is the basetag, followed by a dot and then the index
sprintf(_languageIndex[_languageIndexSize].tag, "%s.%03d", baseTag, idx); Common::sprintf_s(_languageIndex[_languageIndexSize].tag, "%s.%03d", baseTag, idx);
// That was another index entry // That was another index entry
_languageIndexSize++; _languageIndexSize++;