aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-08-11 02:30:07 +0200
committerEinar Johan Trøan Sømåen2012-08-11 02:30:07 +0200
commitc422ae9d8a90aeb63da3e3fdf521323fe6769828 (patch)
tree9ef6303f4d84bb32f4fb9b2dfea37dc9b5f5ce45 /engines
parentd95a2ddef84bb786979affddd95074da79032560 (diff)
downloadscummvm-rg350-c422ae9d8a90aeb63da3e3fdf521323fe6769828.tar.gz
scummvm-rg350-c422ae9d8a90aeb63da3e3fdf521323fe6769828.tar.bz2
scummvm-rg350-c422ae9d8a90aeb63da3e3fdf521323fe6769828.zip
WINTERMUTE: Get rid of strncpy+manual termination.
Diffstat (limited to 'engines')
-rw-r--r--engines/wintermute/ad/ad_sentence.cpp3
-rw-r--r--engines/wintermute/base/base_parser.cpp6
-rw-r--r--engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp3
-rw-r--r--engines/wintermute/detection.cpp4
-rw-r--r--engines/wintermute/utils/utils.cpp2
5 files changed, 7 insertions, 11 deletions
diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp
index d243aaf8e6..60c4519823 100644
--- a/engines/wintermute/ad/ad_sentence.cpp
+++ b/engines/wintermute/ad/ad_sentence.cpp
@@ -184,8 +184,7 @@ char *AdSentence::getStance(int stance) {
_tempStance = new char [curr - start + 1];
if (_tempStance) {
- _tempStance[curr - start] = '\0';
- strncpy(_tempStance, start, curr - start);
+ Common::strlcpy(_tempStance, start, curr - start + 1);
}
return _tempStance;
diff --git a/engines/wintermute/base/base_parser.cpp b/engines/wintermute/base/base_parser.cpp
index 1b39b55768..75268f6483 100644
--- a/engines/wintermute/base/base_parser.cpp
+++ b/engines/wintermute/base/base_parser.cpp
@@ -386,8 +386,7 @@ int BaseParser::scanStr(const char *in, const char *format, ...) {
in++;
const char *in2 = strchr(in, '\'');
if (in2) {
- strncpy(a, in, (int)(in2 - in));
- a[(int)(in2 - in)] = 0;
+ Common::strlcpy(a, in, (int)(in2 - in) + 1);
in = in2 + 1;
} else {
strcpy(a, in);
@@ -395,8 +394,7 @@ int BaseParser::scanStr(const char *in, const char *format, ...) {
}
} else {
const char *in2 = in + strspn(in, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789.");
- strncpy(a, in, (int)(in2 - in));
- a[(int)(in2 - in)] = 0;
+ Common::strlcpy(a, in, (int)(in2 - in) + 1);
in = in2;
}
in += strspn(in, " \t\n\f");
diff --git a/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp b/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp
index afe5e65467..557d9b9b57 100644
--- a/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp
+++ b/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp
@@ -261,8 +261,7 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt
stack->pushNULL();
} else {
char *str = new char[length + 1];
- strncpy(str, (const char *)_buffer + start, length);
- str[length] = '\0';
+ Common::strlcpy(str, (const char *)_buffer + start, length + 1);
stack->pushString(str);
delete[] str;
}
diff --git a/engines/wintermute/detection.cpp b/engines/wintermute/detection.cpp
index af2560fcf2..b3f210d67a 100644
--- a/engines/wintermute/detection.cpp
+++ b/engines/wintermute/detection.cpp
@@ -124,13 +124,13 @@ public:
}
// Prefix to avoid collisions with actually known games
name = "wmefan-" + name;
- strncpy(s_fallbackGameIdBuf, name.c_str(), sizeof(s_fallbackGameIdBuf) - 1);
+ Common::strlcpy(s_fallbackGameIdBuf, name.c_str(), sizeof(s_fallbackGameIdBuf) - 1);
s_fallbackDesc.gameid = s_fallbackGameIdBuf;
if (caption != name) {
caption += " (fangame) ";
char *offset = s_fallbackGameIdBuf + name.size() + 1;
uint32 remainingLength = (sizeof(s_fallbackGameIdBuf) - 1) - (name.size() + 1);
- strncpy(offset, caption.c_str(), remainingLength);
+ Common::strlcpy(offset, caption.c_str(), remainingLength);
s_fallbackDesc.extra = offset;
s_fallbackDesc.flags |= ADGF_USEEXTRAASTITLE;
}
diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp
index f8a7b0e547..4546750c61 100644
--- a/engines/wintermute/utils/utils.cpp
+++ b/engines/wintermute/utils/utils.cpp
@@ -112,7 +112,7 @@ char *BaseUtils::strEntry(int entry, const char *str, const char delim) {
if (start) {
char *ret = new char[len + 1];
memset(ret, 0, len + 1);
- strncpy(ret, start, len);
+ Common::strlcpy(ret, start, len + 1);
return ret;
}
}