QUEEN: Don't use unsafe sprintf and vsprintf

This commit is contained in:
Le Philousophe 2022-10-23 15:26:04 +02:00 committed by Eugene Sandulenko
parent 9a5f51864a
commit 1f45b787b9
7 changed files with 20 additions and 20 deletions

View File

@ -101,10 +101,10 @@ void Display::dynalumInit(const char *roomName, uint16 roomNum) {
if (!isPalFadingDisabled(roomNum)) {
char filename[20];
sprintf(filename, "%s.MSK", roomName);
Common::sprintf_s(filename, "%s.MSK", roomName);
if (_vm->resource()->fileExists(filename)) {
_dynalum.mskBuf = (uint8 *)_vm->resource()->loadFile(filename, 0, &_dynalum.mskSize);
sprintf(filename, "%s.LUM", roomName);
Common::sprintf_s(filename, "%s.LUM", roomName);
if (_vm->resource()->fileExists(filename)) {
_dynalum.lumBuf = (int8 *)_vm->resource()->loadFile(filename, 0, &_dynalum.lumSize);
_dynalum.valid = true;
@ -702,7 +702,7 @@ void Display::setupPanel() {
uint32 dataSize;
char dataName[20];
sprintf(dataName, "PANEL.%s", _imageExt);
Common::sprintf_s(dataName, "PANEL.%s", _imageExt);
uint8 *data = _vm->resource()->loadFile(dataName, 0, &dataSize);
if (_vm->resource()->getPlatform() == Common::kPlatformAmiga) {
@ -721,7 +721,7 @@ void Display::setupNewRoom(const char *name, uint16 room) {
uint32 dataSize;
char dataName[20];
sprintf(dataName, "%s.%s", name, _imageExt);
Common::sprintf_s(dataName, "%s.%s", name, _imageExt);
uint8 *data = _vm->resource()->loadFile(dataName, 0, &dataSize);
if (_vm->resource()->getPlatform() == Common::kPlatformAmiga) {

View File

@ -672,7 +672,7 @@ void Graphics::setupNewRoom(const char *room, uint16 roomNum, int16 *furniture,
// load/setup objects associated to this room
char filename[20];
sprintf(filename, "%s.BBK", room);
Common::sprintf_s(filename, "%s.BBK", room);
_vm->bankMan()->load(filename, 15);
_numFrames = FRAMES_JOE + 1;

View File

@ -182,7 +182,7 @@ void Journal::drawSaveDescriptions() {
for (int i = 0; i < NUM_SAVES_PER_PAGE; ++i) {
int n = _currentSavePage * 10 + i;
char nb[4];
sprintf(nb, "%d", n + 1);
Common::sprintf_s(nb, "%d", n + 1);
int y = _textField.y + i * _textField.h;
_vm->display()->setText(_textField.x, y, _saveDescriptions[n], false);
_vm->display()->setText(_textField.x - 27, y + 1, nb, false);
@ -537,7 +537,7 @@ void Journal::drawInfoPanel() {
break;
}
char versionId[13];
sprintf(versionId, "Version %c.%c%c", ver[2], ver[3], ver[4]);
Common::sprintf_s(versionId, "Version %c.%c%c", ver[2], ver[3], ver[4]);
_vm->display()->setTextCentered(156, versionId, false);
}

View File

@ -853,7 +853,7 @@ void Logic::makeJoeSpeak(uint16 descNum, bool objectType) {
descNum += JOE_RESPONSE_MAX;
}
char descFilePrefix[10];
sprintf(descFilePrefix, "JOE%04i", descNum);
Common::sprintf_s(descFilePrefix, "JOE%04i", descNum);
makePersonSpeak(text, nullptr, descFilePrefix);
}

View File

@ -254,7 +254,7 @@ void Resource::seekResourceFile(int num, uint32 offset) {
debug(7, "Opening resource file %d, current %d", num, _currentResourceFileNum);
_resourceFile.close();
char name[20];
sprintf(name, "queen.%d", num);
Common::sprintf_s(name, "queen.%d", num);
if (!_resourceFile.open(name)) {
error("Could not open resource file '%s'", name);
}

View File

@ -608,7 +608,7 @@ void AmigaSound::updateMusic() {
void AmigaSound::playSound(const char *base) {
debug(7, "AmigaSound::playSound(%s)", base);
char soundName[20];
sprintf(soundName, "%s.AMR", base);
Common::sprintf_s(soundName, "%s.AMR", base);
uint32 soundSize;
Common::File *f = _vm->resource()->findSound(soundName, &soundSize);
@ -629,13 +629,13 @@ Audio::AudioStream *AmigaSound::loadModule(const char *base, int num) {
// load song/pattern data
uint32 sngDataSize;
sprintf(name, "%s.SNG", base);
Common::sprintf_s(name, "%s.SNG", base);
uint8 *sngData = _vm->resource()->loadFile(name, 0, &sngDataSize);
Common::MemoryReadStream sngStr(sngData, sngDataSize);
// load instruments/wave data
uint32 insDataSize;
sprintf(name, "%s.INS", base);
Common::sprintf_s(name, "%s.INS", base);
uint8 *insData = _vm->resource()->loadFile(name, 0, &insDataSize);
Common::MemoryReadStream insStr(insData, insDataSize);

View File

@ -132,13 +132,13 @@ void Talk::talk(const char *filename, int personInRoom, char *cutawayFilename) {
findDialogueString(_person1PtrOff, head, _pMax, _talkString[0]);
if (hasTalkedTo() && head == 1)
sprintf(otherVoiceFilePrefix, "%2dXXXXP", _talkKey);
Common::sprintf_s(otherVoiceFilePrefix, "%2dXXXXP", _talkKey);
else
sprintf(otherVoiceFilePrefix, "%2d%4xP", _talkKey, head);
Common::sprintf_s(otherVoiceFilePrefix, "%2d%4xP", _talkKey, head);
if (_talkString[0][0] == '\0' && retval > 1) {
findDialogueString(_person1PtrOff, retval, _pMax, _talkString[0]);
sprintf(otherVoiceFilePrefix,"%2d%4xP", _talkKey, retval);
Common::sprintf_s(otherVoiceFilePrefix,"%2d%4xP", _talkKey, retval);
}
// Joe dialogue
@ -151,7 +151,7 @@ void Talk::talk(const char *filename, int personInRoom, char *cutawayFilename) {
if (index < 0 && _vm->logic()->gameState(ABS(index)) != _dialogueTree[level][i].gameStateValue)
_talkString[i][0] = '\0';
sprintf(_joeVoiceFilePrefix[i], "%2d%4xJ", _talkKey, _dialogueTree[level][i].head);
Common::sprintf_s(_joeVoiceFilePrefix[i], "%2d%4xJ", _talkKey, _dialogueTree[level][i].head);
}
// Check to see if (all the dialogue options have been selected.
@ -247,7 +247,7 @@ void Talk::talk(const char *filename, int personInRoom, char *cutawayFilename) {
if (-1 == retval) {
findDialogueString(_person1PtrOff, head, _pMax, _talkString[0]);
if (_talkString[0][0] != '\0') {
sprintf(otherVoiceFilePrefix, "%2d%4xP", _talkKey, head);
Common::sprintf_s(otherVoiceFilePrefix, "%2d%4xP", _talkKey, head);
speak(_talkString[0], &person, otherVoiceFilePrefix);
}
}
@ -435,14 +435,14 @@ void Talk::initialTalk() {
// Not yet talked to this person
if (joeString[0] != '0') {
char voiceFilePrefix[MAX_STRING_SIZE];
sprintf(voiceFilePrefix, "%2dSSSSJ", _talkKey);
Common::sprintf_s(voiceFilePrefix, "%2dSSSSJ", _talkKey);
speak(joeString, nullptr, voiceFilePrefix);
}
} else {
// Already spoken to them, choose second response
if (joe2String[0] != '0') {
char voiceFilePrefix[MAX_STRING_SIZE];
sprintf(voiceFilePrefix, "%2dXXXXJ", _talkKey);
Common::sprintf_s(voiceFilePrefix, "%2dXXXXJ", _talkKey);
speak(joe2String, nullptr, voiceFilePrefix);
}
}
@ -789,7 +789,7 @@ void Talk::speakSegment(
segment[length] = '\0';
char voiceFileName[MAX_STRING_SIZE];
sprintf(voiceFileName, "%s%1x", voiceFilePrefix, index + 1);
Common::sprintf_s(voiceFileName, "%s%1x", voiceFilePrefix, index + 1);
// French talkie version has a useless voice file ; c30e_102 file is the same as c30e_101,
// so there is no need to play it. This voice was used in room 30 (N8) when talking to Klunk.