[Scummvm-cvs-logs] SF.net SVN: scummvm:[48955] scummvm/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Wed May 5 19:54:14 CEST 2010


Revision: 48955
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48955&view=rev
Author:   lordhoto
Date:     2010-05-05 17:54:12 +0000 (Wed, 05 May 2010)

Log Message:
-----------
Replace various strncpy usages by strlcpy.

Modified Paths:
--------------
    scummvm/trunk/backends/keymapper/action.cpp
    scummvm/trunk/backends/keymapper/hardware-key.h
    scummvm/trunk/backends/midi/timidity.cpp
    scummvm/trunk/common/unarj.cpp
    scummvm/trunk/engines/engine.cpp
    scummvm/trunk/sound/softsynth/mt32/synth.cpp
    scummvm/trunk/sound/softsynth/mt32/tables.cpp

Modified: scummvm/trunk/backends/keymapper/action.cpp
===================================================================
--- scummvm/trunk/backends/keymapper/action.cpp	2010-05-05 17:53:30 UTC (rev 48954)
+++ scummvm/trunk/backends/keymapper/action.cpp	2010-05-05 17:54:12 UTC (rev 48955)
@@ -38,7 +38,7 @@
 	assert(i);
 	assert(_boss);
 
-	strncpy(id, i, ACTION_ID_SIZE);
+	Common::strlcpy(id, i, ACTION_ID_SIZE);
 
 	_boss->addAction(this);
 }

Modified: scummvm/trunk/backends/keymapper/hardware-key.h
===================================================================
--- scummvm/trunk/backends/keymapper/hardware-key.h	2010-05-05 17:53:30 UTC (rev 48954)
+++ scummvm/trunk/backends/keymapper/hardware-key.h	2010-05-05 17:54:12 UTC (rev 48955)
@@ -60,7 +60,7 @@
 				KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType)
 		: key(ky), description(desc), type(typ), preferredAction(prefAct) {
 		assert(i);
-		strncpy(hwKeyId, i, HWKEY_ID_SIZE);
+		Common::strlcpy(hwKeyId, i, HWKEY_ID_SIZE);
 	}
 };
 

Modified: scummvm/trunk/backends/midi/timidity.cpp
===================================================================
--- scummvm/trunk/backends/midi/timidity.cpp	2010-05-05 17:53:30 UTC (rev 48954)
+++ scummvm/trunk/backends/midi/timidity.cpp	2010-05-05 17:54:12 UTC (rev 48955)
@@ -38,6 +38,7 @@
 
 #include "common/util.h"
 #include "common/endian.h"
+#include "common/str.h"
 #include "sound/musicplugin.h"
 #include "sound/mpu401.h"
 
@@ -154,12 +155,10 @@
 
 	/* get server hostname; if not specified in env, use default */
 	if ((res = getenv("TIMIDITY_HOST")) == NULL)
-		strncpy(timidity_host, DEFAULT_TIMIDITY_HOST, MAXHOSTNAMELEN);
+		Common::strlcpy(timidity_host, DEFAULT_TIMIDITY_HOST, sizeof(timidity_host));
 	else
-		strncpy(timidity_host, res, sizeof(timidity_host));
+		Common::strlcpy(timidity_host, res, sizeof(timidity_host));
 
-	timidity_host[sizeof(timidity_host) - 1] = '\0';
-
 	/* extract control port */
 	if ((res = strrchr(timidity_host, ':')) != NULL) {
 		*res++ = '\0';

Modified: scummvm/trunk/common/unarj.cpp
===================================================================
--- scummvm/trunk/common/unarj.cpp	2010-05-05 17:53:30 UTC (rev 48954)
+++ scummvm/trunk/common/unarj.cpp	2010-05-05 17:54:12 UTC (rev 48955)
@@ -303,10 +303,9 @@
 		return NULL;
 	}
 
-	strncpy(header.filename, (const char *)&headData[header.firstHdrSize], ARJ_FILENAME_MAX);
+	Common::strlcpy(header.filename, (const char *)&headData[header.firstHdrSize], ARJ_FILENAME_MAX);
+	Common::strlcpy(header.comment, (const char *)&headData[header.firstHdrSize + strlen(header.filename) + 1], ARJ_COMMENT_MAX);
 
-	strncpy(header.comment, (const char *)&headData[header.firstHdrSize + strlen(header.filename) + 1], ARJ_COMMENT_MAX);
-
 	// Process extended headers, if any
 	uint16 extHeaderSize;
 	while ((extHeaderSize = stream.readUint16LE()) != 0)

Modified: scummvm/trunk/engines/engine.cpp
===================================================================
--- scummvm/trunk/engines/engine.cpp	2010-05-05 17:53:30 UTC (rev 48954)
+++ scummvm/trunk/engines/engine.cpp	2010-05-05 17:54:12 UTC (rev 48955)
@@ -41,6 +41,7 @@
 #include "common/timer.h"
 #include "common/savefile.h"
 #include "common/system.h"
+#include "common/str.h"
 
 #include "gui/debugger.h"
 #include "gui/message.h"
@@ -63,7 +64,7 @@
 	if (g_engine) {
 		g_engine->errorString(src, dst, dstSize);
 	} else {
-		strncpy(dst, src, dstSize);
+		Common::strlcpy(dst, src, dstSize);
 	}
 }
 
@@ -327,7 +328,7 @@
 		if (getcwd(buffer, MAXPATHLEN) == NULL)
 			return;
 	} else
-		strncpy(buffer, gameDataDir.getPath().c_str(), MAXPATHLEN);
+		Common::strlcpy(buffer, gameDataDir.getPath().c_str(), sizeof(buffer));
 
 	for (i = 0; i < MAXPATHLEN - 1; i++) {
 		if (buffer[i] == '\\')
@@ -366,9 +367,7 @@
 }
 
 void Engine::errorString(const char *buf1, char *buf2, int size) {
-	strncpy(buf2, buf1, size);
-	if (size > 0)
-		buf2[size-1] = '\0';
+	Common::strlcpy(buf2, buf1, size);
 }
 
 void Engine::pauseEngine(bool pause) {

Modified: scummvm/trunk/sound/softsynth/mt32/synth.cpp
===================================================================
--- scummvm/trunk/sound/softsynth/mt32/synth.cpp	2010-05-05 17:53:30 UTC (rev 48954)
+++ scummvm/trunk/sound/softsynth/mt32/synth.cpp	2010-05-05 17:54:12 UTC (rev 48955)
@@ -25,6 +25,8 @@
 
 #include "mt32emu.h"
 
+#include "common/str.h"
+
 #if defined(MACOSX) || defined(SOLARIS) || defined(__MINGW32__)
 // Older versions of Mac OS X didn't supply a powf function, so using it
 // will cause a binary incompatibility when trying to run a binary built
@@ -345,8 +347,7 @@
 	memcpy(&timbre->common, mem, 14);
 	unsigned int memPos = 14;
 	char drumname[11];
-	strncpy(drumname, timbre->common.name, 10);
-	drumname[10] = 0;
+	Common::strlcpy(drumname, timbre->common.name, 11);
 	for (int t = 0; t < 4; t++) {
 		if (((timbre->common.pmute >> t) & 0x1) == 0x1) {
 			if (memPos + 58 >= memLen) {

Modified: scummvm/trunk/sound/softsynth/mt32/tables.cpp
===================================================================
--- scummvm/trunk/sound/softsynth/mt32/tables.cpp	2010-05-05 17:53:30 UTC (rev 48954)
+++ scummvm/trunk/sound/softsynth/mt32/tables.cpp	2010-05-05 17:54:12 UTC (rev 48955)
@@ -614,7 +614,7 @@
 
 	File *file = NULL;
 	char header[20];
-	strncpy(header, "MT32WAVE", 8);
+	memcpy(header, "MT32WAVE", 8);
 	int pos = 8;
 	// Version...
 	for (int i = 0; i < 4; i++)


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