[Scummvm-cvs-logs] SF.net SVN: scummvm:[53490] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Fri Oct 15 15:54:23 CEST 2010


Revision: 53490
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53490&view=rev
Author:   drmccoy
Date:     2010-10-15 13:54:23 +0000 (Fri, 15 Oct 2010)

Log Message:
-----------
GOB: Remove strncpy0()

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

Modified Paths:
--------------
    scummvm/trunk/engines/gob/dataio.cpp
    scummvm/trunk/engines/gob/draw.cpp
    scummvm/trunk/engines/gob/draw_v1.cpp
    scummvm/trunk/engines/gob/draw_v2.cpp
    scummvm/trunk/engines/gob/game.cpp
    scummvm/trunk/engines/gob/goblin.cpp
    scummvm/trunk/engines/gob/helper.h
    scummvm/trunk/engines/gob/hotspots.cpp
    scummvm/trunk/engines/gob/inter_playtoons.cpp
    scummvm/trunk/engines/gob/inter_v1.cpp
    scummvm/trunk/engines/gob/inter_v2.cpp
    scummvm/trunk/engines/gob/inter_v4.cpp
    scummvm/trunk/engines/gob/inter_v6.cpp
    scummvm/trunk/engines/gob/sound/cdrom.cpp
    scummvm/trunk/engines/gob/variables.cpp

Modified: scummvm/trunk/engines/gob/dataio.cpp
===================================================================
--- scummvm/trunk/engines/gob/dataio.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/dataio.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 
 #include "gob/gob.h"
 #include "gob/dataio.h"
@@ -393,7 +394,7 @@
 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 chunkSize;
 	int32 packSize = -1;
 
-	strncpy0(buf, name, 127);
+	Common::strlcpy(buf, name, 128);
 
 	chunkSize = getChunkSize(buf, packSize);
 	if (chunkSize >= 0)

Modified: scummvm/trunk/engines/gob/draw.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/draw.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 
 #include "gob/gob.h"
 #include "gob/draw.h"
@@ -470,10 +471,8 @@
 			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();

Modified: scummvm/trunk/engines/gob/draw_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw_v1.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/draw_v1.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 #include "graphics/cursorman.h"
 
 #include "gob/gob.h"
@@ -258,7 +259,7 @@
 			} 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;
 

Modified: scummvm/trunk/engines/gob/draw_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw_v2.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/draw_v2.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 #include "graphics/cursorman.h"
 
 #include "gob/gob.h"
@@ -550,7 +551,7 @@
 				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));

Modified: scummvm/trunk/engines/gob/game.cpp
===================================================================
--- scummvm/trunk/engines/gob/game.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/game.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 
 #include "gob/gob.h"
 #include "gob/game.h"
@@ -360,8 +361,7 @@
 			if (_totToLoad[0] == 0)
 				break;
 
-			strncpy(_curTotFile, _totToLoad, 14);
-			_curTotFile[13] = '\0';
+			Common::strlcpy(_curTotFile, _totToLoad, 14);
 
 		}
 	} else {
@@ -375,8 +375,7 @@
 			_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 @@
 	if (flags & 1)
 		_vm->_inter->_variables = 0;
 
-	strncpy0(_curTotFile, newTotFile, 9);
+	Common::strlcpy(_curTotFile, newTotFile, 10);
 	strcat(_curTotFile, ".TOT");
 
 	if (_vm->_inter->_terminate != 0) {

Modified: scummvm/trunk/engines/gob/goblin.cpp
===================================================================
--- scummvm/trunk/engines/gob/goblin.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/goblin.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -23,6 +23,8 @@
  *
  */
 
+#include "common/str.h"
+
 #include "gob/gob.h"
 #include "gob/goblin.h"
 #include "gob/helper.h"
@@ -1186,7 +1188,7 @@
 
 	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);

Modified: scummvm/trunk/engines/gob/helper.h
===================================================================
--- scummvm/trunk/engines/gob/helper.h	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/helper.h	2010-10-15 13:54:23 UTC (rev 53490)
@@ -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

Modified: scummvm/trunk/engines/gob/hotspots.cpp
===================================================================
--- scummvm/trunk/engines/gob/hotspots.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/hotspots.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -23,6 +23,8 @@
  *
  */
 
+#include "common/str.h"
+
 #include "gob/hotspots.h"
 #include "gob/global.h"
 #include "gob/helper.h"
@@ -880,10 +882,10 @@
 
 	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 @@
 	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 @@
 
 		// 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;

Modified: scummvm/trunk/engines/gob/inter_playtoons.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_playtoons.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/inter_playtoons.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 
 #include "gui/message.h"
 
@@ -415,9 +416,9 @@
 	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 @@
 	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");

Modified: scummvm/trunk/engines/gob/inter_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v1.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/inter_v1.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 #include "common/file.h"
 
 #include "gob/gob.h"
@@ -971,7 +972,7 @@
 	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 @@
 	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();

Modified: scummvm/trunk/engines/gob/inter_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v2.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/inter_v2.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 
 #include "gui/message.h"
 
@@ -530,7 +531,7 @@
 	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 @@
 
 	_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 @@
 	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 @@
 
 	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 @@
 
 	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 @@
 	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");

Modified: scummvm/trunk/engines/gob/inter_v4.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v4.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/inter_v4.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 #include "common/file.h"
 
 #include "gob/gob.h"
@@ -145,7 +146,7 @@
 	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".

Modified: scummvm/trunk/engines/gob/inter_v6.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v6.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/inter_v6.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 #include "common/file.h"
 #include "graphics/dither.h"
 
@@ -104,7 +105,7 @@
 	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 @@
 	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");
 

Modified: scummvm/trunk/engines/gob/sound/cdrom.cpp
===================================================================
--- scummvm/trunk/engines/gob/sound/cdrom.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/sound/cdrom.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 #include "common/util.h"
 #include "sound/audiocd.h"
 
@@ -92,7 +93,7 @@
 		return;
 	}
 
-	strncpy0(_curTrack, trackName, 15);
+	Common::strlcpy(_curTrack, trackName, 16);
 
 	stopPlaying();
 	_curTrackBuffer = matchPtr;

Modified: scummvm/trunk/engines/gob/variables.cpp
===================================================================
--- scummvm/trunk/engines/gob/variables.cpp	2010-10-15 13:11:34 UTC (rev 53489)
+++ scummvm/trunk/engines/gob/variables.cpp	2010-10-15 13:54:23 UTC (rev 53490)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "common/str.h"
 
 #include "gob/gob.h"
 #include "gob/variables.h"
@@ -112,7 +113,7 @@
 }
 
 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 {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list