From 7da8c8949b56835cf87f88ffd6cfb8204c711592 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 5 May 2010 17:53:30 +0000 Subject: Replace KYRA's strncpy and strncat usages by strlcpy/strlcat. svn-id: r48954 --- engines/kyra/gui_lok.cpp | 6 ++---- engines/kyra/gui_lol.cpp | 26 +++++++++----------------- engines/kyra/gui_v2.cpp | 3 +-- engines/kyra/kyra_mr.cpp | 13 +++---------- engines/kyra/script.cpp | 3 +-- engines/kyra/script_tim.cpp | 3 +-- engines/kyra/sound_digital.cpp | 3 +-- engines/kyra/text_lok.cpp | 5 ++--- 8 files changed, 20 insertions(+), 42 deletions(-) (limited to 'engines') diff --git a/engines/kyra/gui_lok.cpp b/engines/kyra/gui_lok.cpp index 13cb56c842..c8b7e8ec4f 100644 --- a/engines/kyra/gui_lok.cpp +++ b/engines/kyra/gui_lok.cpp @@ -582,8 +582,7 @@ void GUI_LoK::setupSavegames(Menu &menu, int num) { KyraEngine_v1::SaveHeader header; for (int i = startSlot; i < num && uint(_savegameOffset + i) < _saveSlots.size(); i++) { if ((in = _vm->openSaveForReading(_vm->getSavegameFilename(_saveSlots[i + _savegameOffset]), header))) { - strncpy(savenames[i], header.description.c_str(), ARRAYSIZE(savenames[0])); - savenames[i][34] = 0; + Common::strlcpy(savenames[i], header.description.c_str(), ARRAYSIZE(savenames[0])); Util::convertISOToDOS(savenames[i]); @@ -748,8 +747,7 @@ int GUI_LoK::saveGame(Button *button) { } else { for (int i = 0; i < 5; i++) { if (_menu[2].item[i].saveSlot == _vm->_gameToLoad) { - strncpy(_savegameName, _menu[2].item[i].itemString, 31); - _savegameName[30] = 0; + Common::strlcpy(_savegameName, _menu[2].item[i].itemString, 31); break; } } diff --git a/engines/kyra/gui_lol.cpp b/engines/kyra/gui_lol.cpp index 184e28beec..728b519109 100644 --- a/engines/kyra/gui_lol.cpp +++ b/engines/kyra/gui_lol.cpp @@ -2312,39 +2312,32 @@ int GUI_LoL::runMenu(Menu &menu) { if (_currentMenu == &_gameOptions) { char *s = (char *)_vm->_tempBuffer5120; - strncpy(s, _vm->getLangString(0x406f + _vm->_monsterDifficulty), 30); - s[29] = 0; + Common::strlcpy(s, _vm->getLangString(0x406f + _vm->_monsterDifficulty), 30); _currentMenu->item[_vm->gameFlags().isTalkie ? 0 : 2].itemString = s; s += (strlen(s) + 1); - strncpy(s, _vm->getLangString(_vm->_smoothScrollingEnabled ? 0x4068 : 0x4069), 30); - s[29] = 0; + Common::strlcpy(s, _vm->getLangString(_vm->_smoothScrollingEnabled ? 0x4068 : 0x4069), 30); _currentMenu->item[_vm->gameFlags().isTalkie ? 1 : 3].itemString = s; s += (strlen(s) + 1); - strncpy(s, _vm->getLangString(_vm->_floatingCursorsEnabled ? 0x4068 : 0x4069), 30); - s[29] = 0; + Common::strlcpy(s, _vm->getLangString(_vm->_floatingCursorsEnabled ? 0x4068 : 0x4069), 30); _currentMenu->item[_vm->gameFlags().isTalkie ? 2 : 4].itemString = s; s += (strlen(s) + 1); if (_vm->gameFlags().isTalkie) { - strncpy(s, _vm->getLangString(0x42d6 + _vm->_lang), 30); - s[29] = 0; + Common::strlcpy(s, _vm->getLangString(0x42d6 + _vm->_lang), 30); _currentMenu->item[3].itemString = s; s += (strlen(s) + 1); - strncpy(s, _vm->getLangString(_vm->textEnabled() ? 0x4068 : 0x4069), 30); - s[29] = 0; + Common::strlcpy(s, _vm->getLangString(_vm->textEnabled() ? 0x4068 : 0x4069), 30); _currentMenu->item[4].itemString = s; s += (strlen(s) + 1); } else { - strncpy(s, _vm->getLangString(_vm->_configMusic ? 0x4068 : 0x4069), 30); - s[29] = 0; + Common::strlcpy(s, _vm->getLangString(_vm->_configMusic ? 0x4068 : 0x4069), 30); _currentMenu->item[0].itemString = s; s += (strlen(s) + 1); - strncpy(s, _vm->getLangString(_vm->_configSounds ? 0x4068 : 0x4069), 30); - s[29] = 0; + Common::strlcpy(s, _vm->getLangString(_vm->_configSounds ? 0x4068 : 0x4069), 30); _currentMenu->item[1].itemString = s; s += (strlen(s) + 1); } @@ -2582,8 +2575,7 @@ void GUI_LoL::setupSaveMenuSlots(Menu &menu, int num) { for (int i = startSlot; i < num && _savegameOffset + i - slotOffs < _savegameListSize; ++i) { if (_savegameList[_saveSlots[i + _savegameOffset - slotOffs]]) { - strncpy(s, _savegameList[_saveSlots[i + _savegameOffset - slotOffs]], 80); - s[79] = 0; + Common::strlcpy(s, _savegameList[_saveSlots[i + _savegameOffset - slotOffs]], 80); menu.item[i].itemString = s; s += (strlen(s) + 1); menu.item[i].saveSlot = _saveSlots[i + _savegameOffset - slotOffs]; @@ -2628,7 +2620,7 @@ void GUI_LoL::updateSavegameList() { in = _vm->openSaveForReading(_vm->getSavegameFilename(i), header); if (in) { _savegameList[i] = new char[header.description.size() + 1]; - strncpy(_savegameList[i], header.description.c_str(), header.description.size() + 1); + Common::strlcpy(_savegameList[i], header.description.c_str(), header.description.size() + 1); Util::convertISOToDOS(_savegameList[i]); delete in; } else { diff --git a/engines/kyra/gui_v2.cpp b/engines/kyra/gui_v2.cpp index e1016665a2..de19228d16 100644 --- a/engines/kyra/gui_v2.cpp +++ b/engines/kyra/gui_v2.cpp @@ -457,8 +457,7 @@ void GUI_v2::setupSavegameNames(Menu &menu, int num) { for (int i = startSlot; i < num && uint(_savegameOffset + i) < _saveSlots.size(); ++i) { if ((in = _vm->openSaveForReading(_vm->getSavegameFilename(_saveSlots[i + _savegameOffset]), header)) != 0) { char *s = getTableString(menu.item[i].itemId); - strncpy(s, header.description.c_str(), 80); - s[79] = 0; + Common::strlcpy(s, header.description.c_str(), 80); Util::convertISOToDOS(s); menu.item[i].saveSlot = _saveSlots[i + _savegameOffset]; diff --git a/engines/kyra/kyra_mr.cpp b/engines/kyra/kyra_mr.cpp index a450c14c29..614b5dd19b 100644 --- a/engines/kyra/kyra_mr.cpp +++ b/engines/kyra/kyra_mr.cpp @@ -1297,18 +1297,12 @@ void KyraEngine_MR::restoreGfxRect32x32(int x, int y) { char *KyraEngine_MR::appendLanguage(char *buf, int lang, int bufSize) { assert(lang < _languageExtensionSize); - int size = strlen(buf) + strlen(_languageExtension[lang]); - - if (size > bufSize) { + const int size = Common::strlcat(buf, _languageExtension[lang], bufSize); + if (size >= bufSize) { warning("buffer too small to append language extension"); return 0; } - char *temp = buf + strlen(buf); - bufSize -= strlen(buf); - - strncat(temp, _languageExtension[lang], bufSize); - return buf; } @@ -1318,8 +1312,7 @@ int KyraEngine_MR::loadLanguageFile(const char *file, uint8 *&buffer) { uint32 size = 0; char nBuf[32]; - strncpy(nBuf, file, 32); - nBuf[31] = 0; + Common::strlcpy(nBuf, file, sizeof(nBuf)); buffer = _res->fileData(appendLanguage(nBuf, _lang, sizeof(nBuf)), &size); return buffer ? size : 0 ; diff --git a/engines/kyra/script.cpp b/engines/kyra/script.cpp index d58b04f080..f5e5188fd5 100644 --- a/engines/kyra/script.cpp +++ b/engines/kyra/script.cpp @@ -131,8 +131,7 @@ bool EMCInterpreter::load(const char *filename, EMCData *scriptData, const Commo _scriptData->sysFuncs = opcodes; - strncpy(_scriptData->filename, filename, 13); - _scriptData->filename[12] = 0; + Common::strlcpy(_scriptData->filename, filename, 13); _scriptData = 0; _filename = 0; diff --git a/engines/kyra/script_tim.cpp b/engines/kyra/script_tim.cpp index 343ea9307b..97fefa2a93 100644 --- a/engines/kyra/script_tim.cpp +++ b/engines/kyra/script_tim.cpp @@ -174,8 +174,7 @@ TIM *TIMInterpreter::load(const char *filename, const Common::Arrayfunc[i].avtl = _tim->avtl + _tim->avtl[i]; - strncpy(_tim->filename, filename, 13); - _tim->filename[12] = 0; + Common::strlcpy(_tim->filename, filename, 13); _tim->isLoLOutro = (_vm->gameFlags().gameID == GI_LOL) && !scumm_stricmp(filename, "LOLFINAL.TIM"); _tim->lolCharacter = 0; diff --git a/engines/kyra/sound_digital.cpp b/engines/kyra/sound_digital.cpp index 19d3d29411..5b5a548f4a 100644 --- a/engines/kyra/sound_digital.cpp +++ b/engines/kyra/sound_digital.cpp @@ -458,8 +458,7 @@ int SoundDigital::playSound(const char *filename, uint8 priority, Audio::Mixer:: return -1; } - strncpy(use->filename, filename, sizeof(use->filename)); - use->filename[sizeof(use->filename) - 1] = 0; + Common::strlcpy(use->filename, filename, sizeof(use->filename)); use->priority = priority; Audio::SeekableAudioStream *audioStream = _supportedCodecs[usedCodec].streamFunc(stream, DisposeAfterUse::YES); if (!audioStream) { diff --git a/engines/kyra/text_lok.cpp b/engines/kyra/text_lok.cpp index 874ce387e9..3e45c0f286 100644 --- a/engines/kyra/text_lok.cpp +++ b/engines/kyra/text_lok.cpp @@ -348,10 +348,9 @@ void KyraEngine_LoK::drawSentenceCommand(const char *sentence, int color) { void KyraEngine_LoK::updateSentenceCommand(const char *str1, const char *str2, int color) { char sentenceCommand[500]; - strncpy(sentenceCommand, str1, 500); - sentenceCommand[499] = 0; + Common::strlcpy(sentenceCommand, str1, sizeof(sentenceCommand)); if (str2) - strncat(sentenceCommand, str2, 500 - strlen(sentenceCommand)); + Common::strlcat(sentenceCommand, str2, sizeof(sentenceCommand)); drawSentenceCommand(sentenceCommand, color); _screen->updateScreen(); -- cgit v1.2.3