summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2010-10-01 12:52:48 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2010-10-01 12:52:48 (GMT)
commit0ee4b2f57c83341c5896b9abe552e28874292a12 (patch)
tree9bc2b696d5f1dd703e2c0f71eec0ffb13ca67447 /generic
parentc240909716db63ba2036f34e975de5905b2871dd (diff)
downloadtcl-0ee4b2f57c83341c5896b9abe552e28874292a12.zip
tcl-0ee4b2f57c83341c5896b9abe552e28874292a12.tar.gz
tcl-0ee4b2f57c83341c5896b9abe552e28874292a12.tar.bz2
* generic/tclBasic.c, generic/tclClock.c, generic/tclEncoding.c,
* generic/tclEnv.c, generic/tclLoad.c, generic/tclNamesp.c, * generic/tclObj.c, generic/tclRegexp.c, generic/tclResolve.c, * generic/tclResult.c, generic/tclUtil.c, macosx/tclMacOSXFCmd.c: More purging of strcpy() from locations where we already know the length of the data being copied.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclBasic.c8
-rw-r--r--generic/tclClock.c4
-rw-r--r--generic/tclEncoding.c6
-rw-r--r--generic/tclEnv.c21
-rw-r--r--generic/tclLoad.c46
-rw-r--r--generic/tclNamesp.c7
-rw-r--r--generic/tclObj.c6
-rw-r--r--generic/tclRegexp.c4
-rw-r--r--generic/tclResolve.c8
-rw-r--r--generic/tclResult.c4
-rw-r--r--generic/tclUtil.c23
11 files changed, 73 insertions, 64 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index e426178..f0d3e5d 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -16,7 +16,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBasic.c,v 1.466 2010/09/27 19:42:37 msofer Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.467 2010/10/01 12:52:49 dkf Exp $
*/
#include "tclInt.h"
@@ -832,8 +832,8 @@ Tcl_CreateInterp(void)
if (mathfuncNSPtr == NULL) {
Tcl_Panic("Can't create math function namespace");
}
- strcpy(mathFuncName, "::tcl::mathfunc::");
#define MATH_FUNC_PREFIX_LEN 17 /* == strlen("::tcl::mathfunc::") */
+ memcpy(mathFuncName, "::tcl::mathfunc::", MATH_FUNC_PREFIX_LEN);
for (builtinFuncPtr = BuiltinFuncTable; builtinFuncPtr->name != NULL;
builtinFuncPtr++) {
strcpy(mathFuncName+MATH_FUNC_PREFIX_LEN, builtinFuncPtr->name);
@@ -847,12 +847,12 @@ Tcl_CreateInterp(void)
*/
mathopNSPtr = Tcl_CreateNamespace(interp, "::tcl::mathop", NULL, NULL);
-#define MATH_OP_PREFIX_LEN 15 /* == strlen("::tcl::mathop::") */
if (mathopNSPtr == NULL) {
Tcl_Panic("can't create math operator namespace");
}
Tcl_Export(interp, mathopNSPtr, "*", 1);
- strcpy(mathFuncName, "::tcl::mathop::");
+#define MATH_OP_PREFIX_LEN 15 /* == strlen("::tcl::mathop::") */
+ memcpy(mathFuncName, "::tcl::mathop::", MATH_OP_PREFIX_LEN);
for (opcmdInfoPtr=mathOpCmds ; opcmdInfoPtr->name!=NULL ; opcmdInfoPtr++){
TclOpCmdClientData *occdPtr = (TclOpCmdClientData *)
ckalloc(sizeof(TclOpCmdClientData));
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 7519da8..a844205 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclClock.c,v 1.75 2010/03/05 14:34:03 dkf Exp $
+ * RCS: @(#) $Id: tclClock.c,v 1.76 2010/10/01 12:52:49 dkf Exp $
*/
#include "tclInt.h"
@@ -280,8 +280,8 @@ TclClockInit(
* Install the commands.
*/
- strcpy(cmdName, "::tcl::clock::");
#define TCL_CLOCK_PREFIX_LEN 14 /* == strlen("::tcl::clock::") */
+ memcpy(cmdName, "::tcl::clock::", TCL_CLOCK_PREFIX_LEN);
for (clockCmdPtr=clockCommands ; clockCmdPtr->name!=NULL ; clockCmdPtr++) {
strcpy(cmdName + TCL_CLOCK_PREFIX_LEN, clockCmdPtr->name);
data->refCount++;
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 11e0c9c..add30e4 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclEncoding.c,v 1.72 2010/09/16 14:49:37 nijtmans Exp $
+ * RCS: @(#) $Id: tclEncoding.c,v 1.73 2010/10/01 12:52:49 dkf Exp $
*/
#include "tclInt.h"
@@ -2019,9 +2019,9 @@ LoadEscapeEncoding(
+ Tcl_DStringLength(&escapeData);
dataPtr = (EscapeEncodingData *) ckalloc(size);
dataPtr->initLen = strlen(init);
- strcpy(dataPtr->init, init);
+ memcpy(dataPtr->init, init, (unsigned) dataPtr->initLen + 1);
dataPtr->finalLen = strlen(final);
- strcpy(dataPtr->final, final);
+ memcpy(dataPtr->final, final, (unsigned) dataPtr->finalLen + 1);
dataPtr->numSubTables =
Tcl_DStringLength(&escapeData) / sizeof(EscapeSubTable);
memcpy(dataPtr->subTables, Tcl_DStringValue(&escapeData),
diff --git a/generic/tclEnv.c b/generic/tclEnv.c
index a64d38d..5a13044 100644
--- a/generic/tclEnv.c
+++ b/generic/tclEnv.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclEnv.c,v 1.43 2010/04/28 11:50:54 nijtmans Exp $
+ * RCS: @(#) $Id: tclEnv.c,v 1.44 2010/10/01 12:52:49 dkf Exp $
*/
#include "tclInt.h"
@@ -163,7 +163,8 @@ TclSetEnv(
const char *value) /* New value for variable (UTF-8). */
{
Tcl_DString envString;
- int index, length, nameLength;
+ unsigned nameLength, valueLength;
+ int index, length;
char *p, *oldValue;
const char *p2;
@@ -220,7 +221,7 @@ TclSetEnv(
Tcl_DStringFree(&envString);
oldValue = environ[index];
- nameLength = length;
+ nameLength = (unsigned) length;
}
/*
@@ -229,18 +230,19 @@ TclSetEnv(
* and set the environ array value.
*/
- p = ckalloc((unsigned) nameLength + strlen(value) + 2);
- strcpy(p, name);
+ valueLength = strlen(value);
+ p = ckalloc(nameLength + valueLength + 2);
+ memcpy(p, name, nameLength);
p[nameLength] = '=';
- strcpy(p+nameLength+1, value);
+ memcpy(p+nameLength+1, value, valueLength+1);
p2 = Tcl_UtfToExternalDString(NULL, p, -1, &envString);
/*
* Copy the native string to heap memory.
*/
- p = ckrealloc(p, strlen(p2) + 1);
- strcpy(p, p2);
+ p = ckrealloc(p, (unsigned) Tcl_DStringLength(&envString) + 1);
+ memcpy(p, p2, (unsigned) Tcl_DStringLength(&envString) + 1);
Tcl_DStringFree(&envString);
#ifdef USE_PUTENV
@@ -412,7 +414,8 @@ TclUnsetEnv(
Tcl_UtfToExternalDString(NULL, string, -1, &envString);
string = ckrealloc(string, (unsigned) Tcl_DStringLength(&envString)+1);
- strcpy(string, Tcl_DStringValue(&envString));
+ memcpy(string, Tcl_DStringValue(&envString),
+ (unsigned) Tcl_DStringLength(&envString)+1);
Tcl_DStringFree(&envString);
putenv(string);
diff --git a/generic/tclLoad.c b/generic/tclLoad.c
index 22f1c86..93dd950 100644
--- a/generic/tclLoad.c
+++ b/generic/tclLoad.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLoad.c,v 1.26 2010/05/19 08:23:09 nijtmans Exp $
+ * RCS: @(#) $Id: tclLoad.c,v 1.27 2010/10/01 12:52:49 dkf Exp $
*/
#include "tclInt.h"
@@ -133,6 +133,7 @@ Tcl_LoadObjCmd(
const char *p, *fullFileName, *packageName;
Tcl_LoadHandle loadHandle;
Tcl_UniChar ch;
+ unsigned len;
if ((objc < 2) || (objc > 4)) {
Tcl_WrongNumArgs(interp, 1, objv, "fileName ?packageName? ?interp?");
@@ -281,8 +282,7 @@ Tcl_LoadObjCmd(
retc = TclGuessPackageName(fullFileName, &pkgName);
if (!retc) {
- Tcl_Obj *splitPtr;
- Tcl_Obj *pkgGuessPtr;
+ Tcl_Obj *splitPtr, *pkgGuessPtr;
int pElements;
const char *pkgGuess;
@@ -354,7 +354,8 @@ Tcl_LoadObjCmd(
symbols[1] = NULL;
Tcl_MutexLock(&packageMutex);
- code = Tcl_LoadFile(interp, objv[1], symbols, 0, &initProc, &loadHandle);
+ code = Tcl_LoadFile(interp, objv[1], symbols, 0, &initProc,
+ &loadHandle);
Tcl_MutexUnlock(&packageMutex);
if (code != TCL_OK) {
goto done;
@@ -365,21 +366,23 @@ Tcl_LoadObjCmd(
*/
pkgPtr = (LoadedPackage *) ckalloc(sizeof(LoadedPackage));
- pkgPtr->fileName =
- ckalloc((unsigned) (strlen(fullFileName) + 1));
- strcpy(pkgPtr->fileName, fullFileName);
- pkgPtr->packageName =
- ckalloc((unsigned) (Tcl_DStringLength(&pkgName) + 1));
- strcpy(pkgPtr->packageName, Tcl_DStringValue(&pkgName));
+ len = strlen(fullFileName) + 1;
+ pkgPtr->fileName = ckalloc(len);
+ memcpy(pkgPtr->fileName, fullFileName, len);
+ len = (unsigned) Tcl_DStringLength(&pkgName) + 1;
+ pkgPtr->packageName = ckalloc(len);
+ memcpy(pkgPtr->packageName, Tcl_DStringValue(&pkgName), len);
pkgPtr->loadHandle = loadHandle;
pkgPtr->initProc = initProc;
- pkgPtr->safeInitProc = (Tcl_PackageInitProc*)
- Tcl_FindSymbol(interp, loadHandle, Tcl_DStringValue(&safeInitName));
- pkgPtr->unloadProc = (Tcl_PackageUnloadProc*)
- Tcl_FindSymbol(interp, loadHandle, Tcl_DStringValue(&unloadName));
+ pkgPtr->safeInitProc = (Tcl_PackageInitProc *)
+ Tcl_FindSymbol(interp, loadHandle,
+ Tcl_DStringValue(&safeInitName));
+ pkgPtr->unloadProc = (Tcl_PackageUnloadProc *)
+ Tcl_FindSymbol(interp, loadHandle,
+ Tcl_DStringValue(&unloadName));
pkgPtr->safeUnloadProc = (Tcl_PackageUnloadProc *)
- Tcl_FindSymbol(interp, loadHandle,
- Tcl_DStringValue(&safeUnloadName));
+ Tcl_FindSymbol(interp, loadHandle,
+ Tcl_DStringValue(&safeUnloadName));
pkgPtr->interpRefCount = 0;
pkgPtr->safeInterpRefCount = 0;
@@ -387,10 +390,12 @@ Tcl_LoadObjCmd(
pkgPtr->nextPtr = firstPackagePtr;
firstPackagePtr = pkgPtr;
Tcl_MutexUnlock(&packageMutex);
+
/*
- * The Tcl_FindSymbol calls may have left a spurious error message
- * in the interpreter result.
+ * The Tcl_FindSymbol calls may have left a spurious error message in
+ * the interpreter result.
*/
+
Tcl_ResetResult(interp);
}
@@ -400,15 +405,14 @@ Tcl_LoadObjCmd(
*/
if (Tcl_IsSafe(target)) {
- if (pkgPtr->safeInitProc != NULL) {
- code = pkgPtr->safeInitProc(target);
- } else {
+ if (pkgPtr->safeInitProc == NULL) {
Tcl_AppendResult(interp,
"can't use package in a safe interpreter: no ",
pkgPtr->packageName, "_SafeInit procedure", NULL);
code = TCL_ERROR;
goto done;
}
+ code = pkgPtr->safeInitProc(target);
} else {
code = pkgPtr->initProc(target);
}
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c
index 6961fd5..2d1ce11 100644
--- a/generic/tclNamesp.c
+++ b/generic/tclNamesp.c
@@ -22,7 +22,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclNamesp.c,v 1.212 2010/08/30 14:02:10 msofer Exp $
+ * RCS: @(#) $Id: tclNamesp.c,v 1.213 2010/10/01 12:52:49 dkf Exp $
*/
#include "tclInt.h"
@@ -706,8 +706,9 @@ Tcl_CreateNamespace(
*/
nsPtr = (Namespace *) ckalloc(sizeof(Namespace));
- nsPtr->name = ckalloc((unsigned) (strlen(simpleName)+1));
- strcpy(nsPtr->name, simpleName);
+ nameLen = strlen(simpleName) + 1;
+ nsPtr->name = ckalloc((unsigned) nameLen);
+ memcpy(nsPtr->name, simpleName, nameLen);
nsPtr->fullName = NULL; /* Set below. */
nsPtr->clientData = clientData;
nsPtr->deleteProc = deleteProc;
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 0aed0c2..58de5d5 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclObj.c,v 1.175 2010/09/27 19:42:38 msofer Exp $
+ * RCS: @(#) $Id: tclObj.c,v 1.176 2010/10/01 12:52:49 dkf Exp $
*/
#include "tclInt.h"
@@ -2355,7 +2355,7 @@ UpdateStringOfDouble(
len = strlen(buffer);
objPtr->bytes = (char *) ckalloc((unsigned) len + 1);
- strcpy(objPtr->bytes, buffer);
+ memcpy(objPtr->bytes, buffer, (unsigned) len + 1);
objPtr->length = len;
}
@@ -2551,7 +2551,7 @@ UpdateStringOfInt(
len = TclFormatInt(buffer, objPtr->internalRep.longValue);
objPtr->bytes = ckalloc((unsigned) len + 1);
- strcpy(objPtr->bytes, buffer);
+ memcpy(objPtr->bytes, buffer, (unsigned) len + 1);
objPtr->length = len;
}
diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c
index 6848960..86ce07c 100644
--- a/generic/tclRegexp.c
+++ b/generic/tclRegexp.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclRegexp.c,v 1.34 2010/02/24 10:32:17 dkf Exp $
+ * RCS: @(#) $Id: tclRegexp.c,v 1.35 2010/10/01 12:52:50 dkf Exp $
*/
#include "tclInt.h"
@@ -990,7 +990,7 @@ CompileRegexp(
tsdPtr->regexps[i+1] = tsdPtr->regexps[i];
}
tsdPtr->patterns[0] = ckalloc((unsigned) length+1);
- strcpy(tsdPtr->patterns[0], string);
+ memcpy(tsdPtr->patterns[0], string, (unsigned) length + 1);
tsdPtr->patLengths[0] = length;
tsdPtr->regexps[0] = regexpPtr;
diff --git a/generic/tclResolve.c b/generic/tclResolve.c
index 7a86427..109948e 100644
--- a/generic/tclResolve.c
+++ b/generic/tclResolve.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclResolve.c,v 1.12 2010/01/29 16:17:20 nijtmans Exp $
+ * RCS: @(#) $Id: tclResolve.c,v 1.13 2010/10/01 12:52:50 dkf Exp $
*/
#include "tclInt.h"
@@ -67,6 +67,7 @@ Tcl_AddInterpResolvers(
{
Interp *iPtr = (Interp *) interp;
ResolverScheme *resPtr;
+ unsigned len;
/*
* Since we're adding a new name resolution scheme, we must force all code
@@ -103,8 +104,9 @@ Tcl_AddInterpResolvers(
*/
resPtr = (ResolverScheme *) ckalloc(sizeof(ResolverScheme));
- resPtr->name = (char *) ckalloc((unsigned)(strlen(name) + 1));
- strcpy(resPtr->name, name);
+ len = strlen(name) + 1;
+ resPtr->name = (char *) ckalloc(len);
+ memcpy(resPtr->name, name, len);
resPtr->cmdResProc = cmdProc;
resPtr->varResProc = varProc;
resPtr->compiledVarResProc = compiledVarProc;
diff --git a/generic/tclResult.c b/generic/tclResult.c
index 18aae6c..ee15190 100644
--- a/generic/tclResult.c
+++ b/generic/tclResult.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclResult.c,v 1.62 2010/09/22 00:57:11 hobbs Exp $
+ * RCS: @(#) $Id: tclResult.c,v 1.63 2010/10/01 12:52:50 dkf Exp $
*/
#include "tclInt.h"
@@ -436,7 +436,7 @@ Tcl_SetResult(
iPtr->result = iPtr->resultSpace;
iPtr->freeProc = 0;
}
- strcpy(iPtr->result, result);
+ memcpy(iPtr->result, result, (unsigned) length+1);
} else {
iPtr->result = (char *) result;
iPtr->freeProc = freeProc;
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index fb4e20b..45cc8a1 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUtil.c,v 1.117 2010/08/22 18:53:26 nijtmans Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.118 2010/10/01 12:52:50 dkf Exp $
*/
#include "tclInt.h"
@@ -1835,8 +1835,6 @@ Tcl_DStringAppend(
* at end. */
{
int newSize;
- char *dst;
- const char *end;
if (length < 0) {
length = strlen(bytes);
@@ -1866,12 +1864,9 @@ Tcl_DStringAppend(
* Copy the new string into the buffer at the end of the old one.
*/
- for (dst = dsPtr->string + dsPtr->length, end = bytes+length;
- bytes < end; bytes++, dst++) {
- *dst = *bytes;
- }
- *dst = '\0';
+ memcpy(dsPtr->string + dsPtr->length, bytes, length);
dsPtr->length += length;
+ dsPtr->string[dsPtr->length] = '\0';
return dsPtr->string;
}
@@ -2076,7 +2071,7 @@ Tcl_DStringResult(
iPtr->freeProc = TCL_DYNAMIC;
} else if (dsPtr->length < TCL_RESULT_SIZE) {
iPtr->result = iPtr->resultSpace;
- strcpy(iPtr->result, dsPtr->string);
+ memcpy(iPtr->result, dsPtr->string, dsPtr->length + 1);
} else {
Tcl_SetResult(interp, dsPtr->string, TCL_VOLATILE);
}
@@ -2266,10 +2261,14 @@ Tcl_PrintDouble(
*/
if (TclIsInfinite(value)) {
+ /*
+ * Remember to copy the terminating NUL too.
+ */
+
if (value < 0) {
- strcpy(dst, "-Inf");
+ memcpy(dst, "-Inf", 5);
} else {
- strcpy(dst, "Inf");
+ memcpy(dst, "Inf", 4);
}
return;
}
@@ -2670,7 +2669,7 @@ UpdateStringOfEndOffset(
char buffer[TCL_INTEGER_SPACE + sizeof("end") + 1];
register int len;
- strcpy(buffer, "end");
+ memcpy(buffer, "end", sizeof("end") + 1);
len = sizeof("end") - 1;
if (objPtr->internalRep.longValue != 0) {
buffer[len++] = '-';