GOB: Remove strncpy0()

Replacing it (and some strncpy + manual terminating) with
Common::strlcpy()

svn-id: r53490
This commit is contained in:
Sven Hesse 2010-10-15 13:54:23 +00:00
parent 04973e85be
commit 5c48c3fd2b
15 changed files with 47 additions and 42 deletions

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "gob/gob.h"
#include "gob/dataio.h"
@ -393,7 +394,7 @@ int32 DataIO::getChunkSize(const char *chunkName, int32 &packSize) {
void DataIO::openDataFile(const char *src, bool itk) {
char path[128];
strncpy0(path, src, 127);
Common::strlcpy(path, src, 128);
if (!strchr(path, '.')) {
path[123] = 0;
strcat(path, ".stk");
@ -556,7 +557,7 @@ int32 DataIO::getDataSize(const char *name) {
int32 chunkSize;
int32 packSize = -1;
strncpy0(buf, name, 127);
Common::strlcpy(buf, name, 128);
chunkSize = getChunkSize(buf, packSize);
if (chunkSize >= 0)

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "gob/gob.h"
#include "gob/draw.h"
@ -470,10 +471,8 @@ void Draw::oPlaytoons_sub_F_1B(uint16 id, int16 left, int16 top, int16 right, in
else
WRITE_VAR(24, (uint32) 0);
WRITE_VAR(25, (uint32) shortId);
if (_hotspotText) {
strncpy(_hotspotText, paramStr, 40);
_hotspotText[39] = 0;
}
if (_hotspotText)
Common::strlcpy(_hotspotText, paramStr, 40);
}
_vm->_inter->funcBlock(0);
_vm->_game->_script->pop();

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "graphics/cursorman.h"
#include "gob/gob.h"
@ -258,7 +259,7 @@ void Draw_v1::printTotText(int16 id) {
} else if (cmd == 1) {
val = READ_LE_UINT16(ptrEnd + 18) * 4;
strncpy0(buf, GET_VARO_STR(val), 19);
Common::strlcpy(buf, GET_VARO_STR(val), 20);
} else {
val = READ_LE_UINT16(ptrEnd + 18) * 4;

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "graphics/cursorman.h"
#include "gob/gob.h"
@ -550,7 +551,7 @@ void Draw_v2::printTotText(int16 id) {
sprintf(buf, "%d", VAR_OFFSET(val));
} else if (cmd == 1) {
val = READ_LE_UINT16(ptrEnd + 18) * 4;
strncpy0(buf, GET_VARO_STR(val), 19);
Common::strlcpy(buf, GET_VARO_STR(val), 20);
} else {
val = READ_LE_UINT16(ptrEnd + 18) * 4;
sprintf(buf, "%d", VAR_OFFSET(val));

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "gob/gob.h"
#include "gob/game.h"
@ -360,8 +361,7 @@ void Game::playTot(int16 skipPlay) {
if (_totToLoad[0] == 0)
break;
strncpy(_curTotFile, _totToLoad, 14);
_curTotFile[13] = '\0';
Common::strlcpy(_curTotFile, _totToLoad, 14);
}
} else {
@ -375,8 +375,7 @@ void Game::playTot(int16 skipPlay) {
_vm->_inter->_terminate = 2;
}
strncpy(_curTotFile, savedTotName, 14);
_curTotFile[13] = '\0';
Common::strlcpy(_curTotFile, savedTotName, 14);
_vm->_inter->_nestLevel = oldNestLevel;
_vm->_inter->_breakFromLevel = oldBreakFrom;
@ -581,7 +580,7 @@ void Game::totSub(int8 flags, const char *newTotFile) {
if (flags & 1)
_vm->_inter->_variables = 0;
strncpy0(_curTotFile, newTotFile, 9);
Common::strlcpy(_curTotFile, newTotFile, 10);
strcat(_curTotFile, ".TOT");
if (_vm->_inter->_terminate != 0) {

View file

@ -23,6 +23,8 @@
*
*/
#include "common/str.h"
#include "gob/gob.h"
#include "gob/goblin.h"
#include "gob/helper.h"
@ -1186,7 +1188,7 @@ void Goblin::loadObjects(const char *source) {
freeObjects();
initList();
strncpy0(_vm->_map->_sourceFile, source, 14);
Common::strlcpy(_vm->_map->_sourceFile, source, 15);
_vm->_map->_sourceFile[strlen(_vm->_map->_sourceFile) - 4] = 0;
_vm->_map->loadMapObjects(source);

View file

@ -28,13 +28,6 @@
namespace Gob {
/** A strncpy that forces the final \0. */
inline char *strncpy0(char *dest, const char *src, size_t n) {
strncpy(dest, src, n);
dest[n] = 0;
return dest;
}
} // End of namespace Gob
#endif // GOB_HELPER_H

View file

@ -23,6 +23,8 @@
*
*/
#include "common/str.h"
#include "gob/hotspots.h"
#include "gob/global.h"
#include "gob/helper.h"
@ -880,10 +882,10 @@ uint16 Hotspots::updateInput(uint16 xPos, uint16 yPos, uint16 width, uint16 heig
while (1) {
// If we the edit field has enough space, add a space for the new character
strncpy0(tempStr, str, 254);
Common::strlcpy(tempStr, str, 255);
strcat(tempStr, " ");
if ((editSize != 0) && strlen(tempStr) > editSize)
strncpy0(tempStr, str, 255);
Common::strlcpy(tempStr, str, 256);
// Clear input area
fillRect(xPos, yPos,
@ -2006,14 +2008,14 @@ void Hotspots::checkStringMatch(const Hotspot &spot, const InputDesc &input,
char tempStr[256];
char spotStr[256];
strncpy0(tempStr, GET_VARO_STR(spot.key), 255);
Common::strlcpy(tempStr, GET_VARO_STR(spot.key), 256);
if (spot.getType() < kTypeInput3NoLeave)
_vm->_util->cleanupStr(tempStr);
uint16 pos = 0;
do {
strncpy0(spotStr, str, 255);
Common::strlcpy(spotStr, str, 256);
pos += strlen(str) + 1;
str += strlen(str) + 1;
@ -2140,7 +2142,7 @@ void Hotspots::updateAllTexts(const InputDesc *inputs) const {
// Get its text
char tempStr[256];
strncpy0(tempStr, GET_VARO_STR(spot.key), 255);
Common::strlcpy(tempStr, GET_VARO_STR(spot.key), 256);
// Coordinates
uint16 x = spot.left;

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "gui/message.h"
@ -415,9 +416,9 @@ void Inter_Playtoons::oPlaytoons_copyFile() {
char fileName2[128];
_vm->_game->_script->evalExpr(0);
strncpy0(fileName1, _vm->_game->_script->getResultStr(), 127);
Common::strlcpy(fileName1, _vm->_game->_script->getResultStr(), 128);
_vm->_game->_script->evalExpr(0);
strncpy0(fileName2, _vm->_game->_script->getResultStr(), 127);
Common::strlcpy(fileName2, _vm->_game->_script->getResultStr(), 128);
warning("Playtoons Stub: copy file from \"%s\" to \"%s\"", fileName1, fileName2);
}
@ -427,7 +428,7 @@ void Inter_Playtoons::oPlaytoons_openItk() {
char *backSlash;
_vm->_game->_script->evalExpr(0);
strncpy0(fileName, _vm->_game->_script->getResultStr(), 124);
Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 124);
if (!strchr(fileName, '.'))
strcat(fileName, ".ITK");

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "common/file.h"
#include "gob/gob.h"
@ -971,7 +972,7 @@ bool Inter_v1::o1_loadTot(OpFuncParams &params) {
if ((_vm->_game->_script->peekByte() & 0x80) != 0) {
_vm->_game->_script->skip(1);
_vm->_game->_script->evalExpr(0);
strncpy0(buf, _vm->_game->_script->getResultStr(), 15);
Common::strlcpy(buf, _vm->_game->_script->getResultStr(), 16);
} else {
size = _vm->_game->_script->readInt8();
memcpy(buf, _vm->_game->_script->readString(size), size);
@ -1512,7 +1513,7 @@ bool Inter_v1::o1_strToLong(OpFuncParams &params) {
int32 res;
strVar = _vm->_game->_script->readVarIndex();
strncpy0(str, GET_VARO_STR(strVar), 19);
Common::strlcpy(str, GET_VARO_STR(strVar), 20);
res = atoi(str);
destVar = _vm->_game->_script->readVarIndex();

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "gui/message.h"
@ -530,7 +531,7 @@ void Inter_v2::o2_readLIC() {
char path[40];
_vm->_game->_script->evalExpr(0);
strncpy0(path, _vm->_game->_script->getResultStr(), 35);
Common::strlcpy(path, _vm->_game->_script->getResultStr(), 36);
strcat(path, ".LIC");
_vm->_sound->cdLoadLIC(path);
@ -963,7 +964,7 @@ void Inter_v2::o2_playImd() {
_vm->_game->_script->evalExpr(0);
_vm->_game->_script->getResultStr()[8] = 0;
strncpy0(imd, _vm->_game->_script->getResultStr(), 127);
Common::strlcpy(imd, _vm->_game->_script->getResultStr(), 128);
VideoPlayer::Properties props;
@ -1031,7 +1032,7 @@ void Inter_v2::o2_openItk() {
char fileName[32];
_vm->_game->_script->evalExpr(0);
strncpy0(fileName, _vm->_game->_script->getResultStr(), 27);
Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 28);
if (!strchr(fileName, '.'))
strcat(fileName, ".ITK");
@ -1462,7 +1463,7 @@ void Inter_v2::o2_loadInfogramesIns(OpGobParams &params) {
varName = _vm->_game->_script->readInt16();
strncpy0(fileName, GET_VAR_STR(varName), 15);
Common::strlcpy(fileName, GET_VAR_STR(varName), 16);
strcat(fileName, ".INS");
_vm->_sound->infogramesLoadInstruments(fileName);
@ -1474,7 +1475,7 @@ void Inter_v2::o2_playInfogrames(OpGobParams &params) {
varName = _vm->_game->_script->readInt16();
strncpy0(fileName, GET_VAR_STR(varName), 15);
Common::strlcpy(fileName, GET_VAR_STR(varName), 16);
strcat(fileName, ".DUM");
_vm->_sound->infogramesLoadSong(fileName);
@ -1560,7 +1561,7 @@ int16 Inter_v2::loadSound(int16 search) {
if (id == -1) {
char sndfile[14];
strncpy0(sndfile, _vm->_game->_script->readString(9), 9);
Common::strlcpy(sndfile, _vm->_game->_script->readString(9), 10);
if (type == SOUND_ADL)
strcat(sndfile, ".ADL");

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "common/file.h"
#include "gob/gob.h"
@ -145,7 +146,7 @@ void Inter_v4::o4_playVmdOrMusic() {
bool close;
_vm->_game->_script->evalExpr(0);
strncpy0(fileName, _vm->_game->_script->getResultStr(), 127);
Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 128);
// WORKAROUND: The nut rolling animation in the administration center
// in Woodruff is called "noixroul", but the scripts think it's "noixroule".

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "common/file.h"
#include "graphics/dither.h"
@ -104,7 +105,7 @@ void Inter_v6::o6_playVmdOrMusic() {
bool close;
_vm->_game->_script->evalExpr(0);
strncpy0(fileName, _vm->_game->_script->getResultStr(), 127);
Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 128);
VideoPlayer::Properties props;
@ -187,7 +188,7 @@ void Inter_v6::o6_openItk() {
char fileName[32];
_vm->_game->_script->evalExpr(0);
strncpy0(fileName, _vm->_game->_script->getResultStr(), 27);
Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 28);
if (!strchr(fileName, '.'))
strcat(fileName, ".ITK");

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "common/util.h"
#include "sound/audiocd.h"
@ -92,7 +93,7 @@ void CDROM::startTrack(const char *trackName) {
return;
}
strncpy0(_curTrack, trackName, 15);
Common::strlcpy(_curTrack, trackName, 16);
stopPlaying();
_curTrackBuffer = matchPtr;

View file

@ -24,6 +24,7 @@
*/
#include "common/endian.h"
#include "common/str.h"
#include "gob/gob.h"
#include "gob/variables.h"
@ -112,7 +113,7 @@ uint32 Variables::readOff32(uint32 offset) const {
}
void Variables::readOffString(uint32 offset, char *value, uint32 length) {
strncpy0(value, (const char *)(_vars + offset), length - 1);
Common::strlcpy(value, (const char *)(_vars + offset), length);
}
const uint8 *Variables::getAddressVar8(uint32 var) const {