aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2010-10-15 13:54:23 +0000
committerSven Hesse2010-10-15 13:54:23 +0000
commit5c48c3fd2b5a229e125455b3f5c23f4773b0191e (patch)
treee046dd5ca61d6f7f78eb61dd9f7b9771168e6dc3
parent04973e85be84db4ac5a71a7012eb68c8e52af3c4 (diff)
downloadscummvm-rg350-5c48c3fd2b5a229e125455b3f5c23f4773b0191e.tar.gz
scummvm-rg350-5c48c3fd2b5a229e125455b3f5c23f4773b0191e.tar.bz2
scummvm-rg350-5c48c3fd2b5a229e125455b3f5c23f4773b0191e.zip
GOB: Remove strncpy0()
Replacing it (and some strncpy + manual terminating) with Common::strlcpy() svn-id: r53490
-rw-r--r--engines/gob/dataio.cpp5
-rw-r--r--engines/gob/draw.cpp7
-rw-r--r--engines/gob/draw_v1.cpp3
-rw-r--r--engines/gob/draw_v2.cpp3
-rw-r--r--engines/gob/game.cpp9
-rw-r--r--engines/gob/goblin.cpp4
-rw-r--r--engines/gob/helper.h7
-rw-r--r--engines/gob/hotspots.cpp12
-rw-r--r--engines/gob/inter_playtoons.cpp7
-rw-r--r--engines/gob/inter_v1.cpp5
-rw-r--r--engines/gob/inter_v2.cpp13
-rw-r--r--engines/gob/inter_v4.cpp3
-rw-r--r--engines/gob/inter_v6.cpp5
-rw-r--r--engines/gob/sound/cdrom.cpp3
-rw-r--r--engines/gob/variables.cpp3
15 files changed, 47 insertions, 42 deletions
diff --git a/engines/gob/dataio.cpp b/engines/gob/dataio.cpp
index 694cec6a6f..4ef1bd95af 100644
--- a/engines/gob/dataio.cpp
+++ b/engines/gob/dataio.cpp
@@ -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)
diff --git a/engines/gob/draw.cpp b/engines/gob/draw.cpp
index 5c918e6b7e..bb357168b7 100644
--- a/engines/gob/draw.cpp
+++ b/engines/gob/draw.cpp
@@ -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();
diff --git a/engines/gob/draw_v1.cpp b/engines/gob/draw_v1.cpp
index 6496229282..e23ae256f3 100644
--- a/engines/gob/draw_v1.cpp
+++ b/engines/gob/draw_v1.cpp
@@ -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;
diff --git a/engines/gob/draw_v2.cpp b/engines/gob/draw_v2.cpp
index bb2a57b790..ece46bef28 100644
--- a/engines/gob/draw_v2.cpp
+++ b/engines/gob/draw_v2.cpp
@@ -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));
diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp
index bf0dc4147c..02ad8562de 100644
--- a/engines/gob/game.cpp
+++ b/engines/gob/game.cpp
@@ -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) {
diff --git a/engines/gob/goblin.cpp b/engines/gob/goblin.cpp
index ee2b4f52c9..f2f561c642 100644
--- a/engines/gob/goblin.cpp
+++ b/engines/gob/goblin.cpp
@@ -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);
diff --git a/engines/gob/helper.h b/engines/gob/helper.h
index d1f24792a5..8d2895bec8 100644
--- a/engines/gob/helper.h
+++ b/engines/gob/helper.h
@@ -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
diff --git a/engines/gob/hotspots.cpp b/engines/gob/hotspots.cpp
index dad141a254..a8972f06ac 100644
--- a/engines/gob/hotspots.cpp
+++ b/engines/gob/hotspots.cpp
@@ -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;
diff --git a/engines/gob/inter_playtoons.cpp b/engines/gob/inter_playtoons.cpp
index befed4b1c2..37e4d04a94 100644
--- a/engines/gob/inter_playtoons.cpp
+++ b/engines/gob/inter_playtoons.cpp
@@ -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");
diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp
index 3bf7fc8fd4..1fe44758df 100644
--- a/engines/gob/inter_v1.cpp
+++ b/engines/gob/inter_v1.cpp
@@ -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();
diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp
index 0003332e47..de20cfae56 100644
--- a/engines/gob/inter_v2.cpp
+++ b/engines/gob/inter_v2.cpp
@@ -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");
diff --git a/engines/gob/inter_v4.cpp b/engines/gob/inter_v4.cpp
index 26eff4f675..8d89cc7b63 100644
--- a/engines/gob/inter_v4.cpp
+++ b/engines/gob/inter_v4.cpp
@@ -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".
diff --git a/engines/gob/inter_v6.cpp b/engines/gob/inter_v6.cpp
index c6d0211c8f..6c02f98b98 100644
--- a/engines/gob/inter_v6.cpp
+++ b/engines/gob/inter_v6.cpp
@@ -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");
diff --git a/engines/gob/sound/cdrom.cpp b/engines/gob/sound/cdrom.cpp
index 8f0b1df23e..3afae927e5 100644
--- a/engines/gob/sound/cdrom.cpp
+++ b/engines/gob/sound/cdrom.cpp
@@ -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;
diff --git a/engines/gob/variables.cpp b/engines/gob/variables.cpp
index 11c5f08bb2..ebcc22c6a1 100644
--- a/engines/gob/variables.cpp
+++ b/engines/gob/variables.cpp
@@ -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 {