aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2010-05-05 17:54:12 +0000
committerJohannes Schickel2010-05-05 17:54:12 +0000
commitcaf31ee5afb61a88342176473bf77ebddc098ca4 (patch)
treebc0ec2794958a722d314af38c00d65a9a058b0cf
parent7da8c8949b56835cf87f88ffd6cfb8204c711592 (diff)
downloadscummvm-rg350-caf31ee5afb61a88342176473bf77ebddc098ca4.tar.gz
scummvm-rg350-caf31ee5afb61a88342176473bf77ebddc098ca4.tar.bz2
scummvm-rg350-caf31ee5afb61a88342176473bf77ebddc098ca4.zip
Replace various strncpy usages by strlcpy.
svn-id: r48955
-rw-r--r--backends/keymapper/action.cpp2
-rw-r--r--backends/keymapper/hardware-key.h2
-rw-r--r--backends/midi/timidity.cpp7
-rw-r--r--common/unarj.cpp5
-rw-r--r--engines/engine.cpp9
-rw-r--r--sound/softsynth/mt32/synth.cpp5
-rw-r--r--sound/softsynth/mt32/tables.cpp2
7 files changed, 15 insertions, 17 deletions
diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp
index 03c5933580..aee4d80356 100644
--- a/backends/keymapper/action.cpp
+++ b/backends/keymapper/action.cpp
@@ -38,7 +38,7 @@ Action::Action(Keymap *boss, const char *i, String des, ActionType typ,
assert(i);
assert(_boss);
- strncpy(id, i, ACTION_ID_SIZE);
+ Common::strlcpy(id, i, ACTION_ID_SIZE);
_boss->addAction(this);
}
diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h
index dc83462de8..7c608a53fc 100644
--- a/backends/keymapper/hardware-key.h
+++ b/backends/keymapper/hardware-key.h
@@ -60,7 +60,7 @@ struct HardwareKey {
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);
}
};
diff --git a/backends/midi/timidity.cpp b/backends/midi/timidity.cpp
index 36d437414f..1a44e62b16 100644
--- a/backends/midi/timidity.cpp
+++ b/backends/midi/timidity.cpp
@@ -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,11 +155,9 @@ int MidiDriver_TIMIDITY::open() {
/* 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));
-
- timidity_host[sizeof(timidity_host) - 1] = '\0';
+ Common::strlcpy(timidity_host, res, sizeof(timidity_host));
/* extract control port */
if ((res = strrchr(timidity_host, ':')) != NULL) {
diff --git a/common/unarj.cpp b/common/unarj.cpp
index 27399036e1..c130533dc1 100644
--- a/common/unarj.cpp
+++ b/common/unarj.cpp
@@ -303,9 +303,8 @@ ArjHeader *readHeader(SeekableReadStream &stream) {
return NULL;
}
- strncpy(header.filename, (const char *)&headData[header.firstHdrSize], ARJ_FILENAME_MAX);
-
- strncpy(header.comment, (const char *)&headData[header.firstHdrSize + strlen(header.filename) + 1], ARJ_COMMENT_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);
// Process extended headers, if any
uint16 extHeaderSize;
diff --git a/engines/engine.cpp b/engines/engine.cpp
index 4cf797758f..0f42cd493d 100644
--- a/engines/engine.cpp
+++ b/engines/engine.cpp
@@ -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 @@ static void defaultOutputFormatter(char *dst, const char *src, size_t dstSize) {
if (g_engine) {
g_engine->errorString(src, dst, dstSize);
} else {
- strncpy(dst, src, dstSize);
+ Common::strlcpy(dst, src, dstSize);
}
}
@@ -327,7 +328,7 @@ void Engine::checkCD() {
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 @@ bool Engine::shouldPerformAutoSave(int lastSaveTime) {
}
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) {
diff --git a/sound/softsynth/mt32/synth.cpp b/sound/softsynth/mt32/synth.cpp
index b3f8d81719..6a16db22ec 100644
--- a/sound/softsynth/mt32/synth.cpp
+++ b/sound/softsynth/mt32/synth.cpp
@@ -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 @@ bool Synth::initRhythmTimbre(int timbreNum, const Bit8u *mem, unsigned int memLe
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) {
diff --git a/sound/softsynth/mt32/tables.cpp b/sound/softsynth/mt32/tables.cpp
index 571750ee99..b0414154dc 100644
--- a/sound/softsynth/mt32/tables.cpp
+++ b/sound/softsynth/mt32/tables.cpp
@@ -614,7 +614,7 @@ bool Tables::initNotes(Synth *synth, PCMWaveEntry *pcmWaves, float rate, float m
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++)