From 3dc03bc4ac97274d4f260b16b1b7f5e5d550666a Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 1 Jul 2018 06:21:55 +0000 Subject: Starting to update all callers of TclGetStringFromObj() to use size_t variables --- generic/tclBasic.c | 5 +++-- generic/tclCmdIL.c | 2 +- generic/tclFileName.c | 6 +++--- generic/tclIO.c | 2 +- generic/tclIOUtil.c | 2 +- generic/tclInt.decls | 2 +- generic/tclInt.h | 14 +++++++++++--- generic/tclIntDecls.h | 4 ++-- generic/tclMain.c | 8 ++++---- generic/tclOODefineCmds.c | 4 ++-- generic/tclObj.c | 21 +++++++++++---------- generic/tclParse.c | 2 +- generic/tclPathObj.c | 41 +++++++++++++++++++++-------------------- generic/tclStringObj.c | 4 ++-- generic/tclUtil.c | 7 +++---- 15 files changed, 67 insertions(+), 57 deletions(-) diff --git a/generic/tclBasic.c b/generic/tclBasic.c index b9f9797..39c8335 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -6265,10 +6265,11 @@ Tcl_AppendObjToErrorInfo( * pertains. */ Tcl_Obj *objPtr) /* Message to record. */ { - const char *message = TclGetString(objPtr); + size_t length; + const char *message = TclGetStringFromObj(objPtr, &length); Tcl_IncrRefCount(objPtr); - Tcl_AddObjErrorInfo(interp, message, objPtr->length); + Tcl_AddObjErrorInfo(interp, message, length); Tcl_DecrRefCount(objPtr); } diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 2eb089a..018a9f5 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -2889,7 +2889,7 @@ Tcl_LsearchObjCmd( Tcl_Obj *const objv[]) /* Argument values. */ { const char *bytes, *patternBytes; - int i, match, index, result=TCL_OK, listc, length, elemLen, bisect; + int i, match, index, result=TCL_OK, listc, length = 0, elemLen, bisect; int allocatedIndexVector = 0; int dataType, isIncreasing, lower, upper, start, groupSize, groupOffset; Tcl_WideInt patWide, objWide; diff --git a/generic/tclFileName.c b/generic/tclFileName.c index 15fcde7..3eb6937 100644 --- a/generic/tclFileName.c +++ b/generic/tclFileName.c @@ -578,7 +578,7 @@ Tcl_SplitPath( size = 1; for (i = 0; i < *argcPtr; i++) { Tcl_ListObjIndex(NULL, resultPtr, i, &eltPtr); - TclGetStringFromObj(eltPtr, &len); + (void)TclGetStringFromObj(eltPtr, &len); size += len + 1; } @@ -885,7 +885,7 @@ TclpNativeJoinPath( if (length > 0 && (start[length-1] != '/')) { Tcl_AppendToObj(prefix, "/", 1); - TclGetStringFromObj(prefix, &length); + (void)TclGetStringFromObj(prefix, &length); } needsSep = 0; @@ -921,7 +921,7 @@ TclpNativeJoinPath( if ((length > 0) && (start[length-1] != '/') && (start[length-1] != ':')) { Tcl_AppendToObj(prefix, "/", 1); - TclGetStringFromObj(prefix, &length); + (void)TclGetStringFromObj(prefix, &length); } needsSep = 0; diff --git a/generic/tclIO.c b/generic/tclIO.c index 17f7469..5a4e1e9 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -4563,7 +4563,7 @@ Tcl_GetsObj( * newline in the available input. */ - TclGetStringFromObj(objPtr, &oldLength); + (void)TclGetStringFromObj(objPtr, &oldLength); oldFlags = statePtr->inputEncodingFlags; oldState = statePtr->inputEncodingState; oldRemoved = BUFFER_PADDING; diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index 3382825..29ba021 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -682,7 +682,7 @@ FsUpdateCwd( Tcl_Obj *cwdObj, ClientData clientData) { - int len; + int len = 0; const char *str = NULL; ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&fsDataKey); diff --git a/generic/tclInt.decls b/generic/tclInt.decls index 54623a4..efc1ac3 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -115,7 +115,7 @@ declare 23 { } # Replaced with macro (see tclInt.h) in Tcl 8.5.0, restored in 8.5.10 declare 24 { - int TclFormatInt(char *buffer, Tcl_WideInt n) + size_t TclFormatInt(char *buffer, Tcl_WideInt n) } declare 25 { void TclFreePackageInfo(Interp *iPtr) diff --git a/generic/tclInt.h b/generic/tclInt.h index 303cff3..899c4d6 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4333,10 +4333,18 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file, #define TclGetString(objPtr) \ ((objPtr)->bytes? (objPtr)->bytes : Tcl_GetString(objPtr)) +#if 0 + static inline const char *TclGetStringFromObj(Tcl_Obj *objPtr, size_t *lenPtr) { + const char *response = Tcl_GetString(objPtr); + if (lenPtr) *lenPtr = objPtr->length; + return response; + } +#else #define TclGetStringFromObj(objPtr, lenPtr) \ - ((objPtr)->bytes \ - ? (*(lenPtr) = (objPtr)->length, (objPtr)->bytes) \ - : Tcl_GetStringFromObj((objPtr), (lenPtr))) + (((objPtr)->bytes \ + ? 0 : Tcl_GetString((objPtr)), \ + *(lenPtr) = (objPtr)->length, (objPtr)->bytes)) +#endif /* *---------------------------------------------------------------- diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h index a0099e8..fd4ab70 100644 --- a/generic/tclIntDecls.h +++ b/generic/tclIntDecls.h @@ -94,7 +94,7 @@ EXTERN int TclFindElement(Tcl_Interp *interp, /* 23 */ EXTERN Proc * TclFindProc(Interp *iPtr, const char *procName); /* 24 */ -EXTERN int TclFormatInt(char *buffer, Tcl_WideInt n); +EXTERN size_t TclFormatInt(char *buffer, Tcl_WideInt n); /* 25 */ EXTERN void TclFreePackageInfo(Interp *iPtr); /* Slot 26 is reserved */ @@ -607,7 +607,7 @@ typedef struct TclIntStubs { void (*reserved21)(void); int (*tclFindElement) (Tcl_Interp *interp, const char *listStr, int listLength, const char **elementPtr, const char **nextPtr, size_t *sizePtr, int *bracePtr); /* 22 */ Proc * (*tclFindProc) (Interp *iPtr, const char *procName); /* 23 */ - int (*tclFormatInt) (char *buffer, Tcl_WideInt n); /* 24 */ + size_t (*tclFormatInt) (char *buffer, Tcl_WideInt n); /* 24 */ void (*tclFreePackageInfo) (Interp *iPtr); /* 25 */ void (*reserved26)(void); void (*reserved27)(void); diff --git a/generic/tclMain.c b/generic/tclMain.c index 9380fb2..b62da93 100644 --- a/generic/tclMain.c +++ b/generic/tclMain.c @@ -532,7 +532,7 @@ Tcl_MainEx( * error messages troubles deeper in, so lop it back off. */ - TclGetStringFromObj(is.commandPtr, &length); + (void)TclGetStringFromObj(is.commandPtr, &length); Tcl_SetObjLength(is.commandPtr, --length); code = Tcl_RecordAndEvalObj(interp, is.commandPtr, TCL_EVAL_GLOBAL); @@ -549,7 +549,7 @@ Tcl_MainEx( } else if (is.tty) { resultPtr = Tcl_GetObjResult(interp); Tcl_IncrRefCount(resultPtr); - TclGetStringFromObj(resultPtr, &length); + (void)TclGetStringFromObj(resultPtr, &length); chan = Tcl_GetStdChannel(TCL_STDOUT); if ((length > 0) && chan) { Tcl_WriteObj(chan, resultPtr); @@ -793,7 +793,7 @@ StdinProc( goto prompt; } isPtr->prompt = PROMPT_START; - TclGetStringFromObj(commandPtr, &length); + (void)TclGetStringFromObj(commandPtr, &length); Tcl_SetObjLength(commandPtr, --length); /* @@ -824,7 +824,7 @@ StdinProc( chan = Tcl_GetStdChannel(TCL_STDOUT); Tcl_IncrRefCount(resultPtr); - TclGetStringFromObj(resultPtr, &length); + (void)TclGetStringFromObj(resultPtr, &length); if ((length > 0) && (chan != NULL)) { Tcl_WriteObj(chan, resultPtr); Tcl_WriteChars(chan, "\n", 1); diff --git a/generic/tclOODefineCmds.c b/generic/tclOODefineCmds.c index 19cd42b..fb2de01 100644 --- a/generic/tclOODefineCmds.c +++ b/generic/tclOODefineCmds.c @@ -1465,7 +1465,7 @@ TclOODefineConstructorObjCmd( } clsPtr = oPtr->classPtr; - TclGetStringFromObj(objv[2], &bodyLength); + (void)TclGetStringFromObj(objv[2], &bodyLength); if (bodyLength > 0) { /* * Create the method structure. @@ -1586,7 +1586,7 @@ TclOODefineDestructorObjCmd( } clsPtr = oPtr->classPtr; - TclGetStringFromObj(objv[1], &bodyLength); + (void)TclGetStringFromObj(objv[1], &bodyLength); if (bodyLength > 0) { /* * Create the method structure. diff --git a/generic/tclObj.c b/generic/tclObj.c index 640900a..857c1f0 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -606,7 +606,8 @@ TclContinuationsEnterDerived( int start, int *clNext) { - int length, end, num; + size_t length; + int end, num; int *wordCLLast = clNext; /* @@ -633,7 +634,7 @@ TclContinuationsEnterDerived( * better way which doesn't shimmer?) */ - TclGetStringFromObj(objPtr, &length); + (void)TclGetStringFromObj(objPtr, &length); end = start + length; /* First char after the word */ /* @@ -1803,7 +1804,7 @@ TclSetBooleanFromAny( badBoolean: if (interp != NULL) { - int length; + size_t length; const char *str = TclGetStringFromObj(objPtr, &length); Tcl_Obj *msg; @@ -1822,8 +1823,8 @@ ParseBoolean( { int newBool; char lowerCase[6]; - const char *str = TclGetString(objPtr); - size_t i, length = objPtr->length; + size_t i, length; + const char *str = TclGetStringFromObj(objPtr, &length); if ((length == 0) || (length > 5)) { /* @@ -2177,14 +2178,14 @@ UpdateStringOfDouble( register Tcl_Obj *objPtr) /* Double obj with string rep to update. */ { char buffer[TCL_DOUBLE_SPACE]; - register int len; + size_t len; Tcl_PrintDouble(NULL, objPtr->internalRep.doubleValue, buffer); len = strlen(buffer); - objPtr->bytes = ckalloc(len + 1); - memcpy(objPtr->bytes, buffer, (unsigned) len + 1); objPtr->length = len; + objPtr->bytes = ckalloc(++len); + memcpy(objPtr->bytes, buffer, len); } /* @@ -2293,13 +2294,13 @@ UpdateStringOfInt( register Tcl_Obj *objPtr) /* Int object whose string rep to update. */ { char buffer[TCL_INTEGER_SPACE]; - register int len; + size_t len; len = TclFormatInt(buffer, objPtr->internalRep.wideValue); + objPtr->length = len; objPtr->bytes = ckalloc(len + 1); memcpy(objPtr->bytes, buffer, (unsigned) len + 1); - objPtr->length = len; } /* diff --git a/generic/tclParse.c b/generic/tclParse.c index dc23f20..7db043b 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -2230,7 +2230,7 @@ TclSubstTokens( if (result == 0) { clPos = 0; } else { - TclGetStringFromObj(result, &clPos); + (void)TclGetStringFromObj(result, &clPos); } if (numCL >= maxNumCL) { diff --git a/generic/tclPathObj.c b/generic/tclPathObj.c index 44d0442..4b648be 100644 --- a/generic/tclPathObj.c +++ b/generic/tclPathObj.c @@ -225,14 +225,14 @@ TclFSNormalizeAbsolutePath( /* * Need to skip '.' in the path. */ - int curLen; + size_t curLen; if (retVal == NULL) { const char *path = TclGetString(pathPtr); retVal = Tcl_NewStringObj(path, dirSep - path); Tcl_IncrRefCount(retVal); } - TclGetStringFromObj(retVal, &curLen); + (void)TclGetStringFromObj(retVal, &curLen); if (curLen == 0) { Tcl_AppendToObj(retVal, dirSep, 1); } @@ -245,7 +245,7 @@ TclFSNormalizeAbsolutePath( } if (dirSep[2] == '.' && IsSeparatorOrNull(dirSep[3])) { Tcl_Obj *linkObj; - int curLen; + size_t curLen; char *linkStr; /* @@ -258,7 +258,7 @@ TclFSNormalizeAbsolutePath( retVal = Tcl_NewStringObj(path, dirSep - path); Tcl_IncrRefCount(retVal); } - TclGetStringFromObj(retVal, &curLen); + (void)TclGetStringFromObj(retVal, &curLen); if (curLen == 0) { Tcl_AppendToObj(retVal, dirSep, 1); } @@ -291,7 +291,7 @@ TclFSNormalizeAbsolutePath( const char *path = TclGetStringFromObj(retVal, &curLen); - while (--curLen >= 0) { + while (curLen-- > 0) { if (IsSeparatorOrNull(path[curLen])) { break; } @@ -324,7 +324,7 @@ TclFSNormalizeAbsolutePath( */ if (tclPlatform == TCL_PLATFORM_WINDOWS) { - int i; + size_t i; for (i = 0; i < curLen; i++) { if (linkStr[i] == '\\') { @@ -342,7 +342,7 @@ TclFSNormalizeAbsolutePath( * not the first character of the path). */ - while (--curLen >= 0) { + while (curLen-- > 0) { if (IsSeparatorOrNull(linkStr[curLen])) { if (curLen) { Tcl_SetObjLength(retVal, curLen); @@ -404,7 +404,7 @@ TclFSNormalizeAbsolutePath( */ if (tclPlatform == TCL_PLATFORM_WINDOWS) { - int len; + size_t len; const char *path = TclGetStringFromObj(retVal, &len); if (len == 2 && path[0] != 0 && path[1] == ':') { @@ -643,7 +643,7 @@ TclPathPart( return GetExtension(fsPathPtr->normPathPtr); case TCL_PATH_ROOT: { const char *fileName, *extension; - int length; + size_t length; fileName = TclGetStringFromObj(fsPathPtr->normPathPtr, &length); @@ -694,7 +694,7 @@ TclPathPart( if (portion == TCL_PATH_EXTENSION) { return GetExtension(pathPtr); } else if (portion == TCL_PATH_ROOT) { - int length; + size_t length; const char *fileName, *extension; fileName = TclGetStringFromObj(pathPtr, &length); @@ -883,7 +883,7 @@ TclJoinPath( if (type == TCL_PATH_RELATIVE) { const char *str; - int len; + size_t len; str = TclGetStringFromObj(tailObj, &len); if (len == 0) { @@ -1096,7 +1096,7 @@ TclJoinPath( if (length > 0 && ptr[length -1] != '/') { Tcl_AppendToObj(res, &separator, 1); - TclGetStringFromObj(res, &length); + (void)TclGetStringFromObj(res, &length); } Tcl_SetObjLength(res, length + strlen(strElt)); @@ -1792,7 +1792,7 @@ Tcl_FSGetNormalizedPath( UpdateStringOfFsPath(pathPtr); } - TclGetStringFromObj(fsPathPtr->normPathPtr, &tailLen); + (void)TclGetStringFromObj(fsPathPtr->normPathPtr, &tailLen); if (tailLen) { copy = AppendPath(dir, fsPathPtr->normPathPtr); } else { @@ -1893,7 +1893,7 @@ Tcl_FSGetNormalizedPath( } fsPathPtr = PATHOBJ(pathPtr); } else if (fsPathPtr->normPathPtr == NULL) { - int cwdLen; + size_t cwdLen; Tcl_Obj *copy; copy = AppendPath(fsPathPtr->cwdPtr, pathPtr); @@ -2001,7 +2001,7 @@ Tcl_FSGetNormalizedPath( */ if (pureNormalized) { - int normPathLen, pathLen; + size_t normPathLen, pathLen; const char *normPath; path = TclGetStringFromObj(pathPtr, &pathLen); @@ -2266,7 +2266,8 @@ Tcl_FSEqualPaths( Tcl_Obj *secondPtr) { const char *firstStr, *secondStr; - int firstLen, secondLen, tempErrno; + size_t firstLen, secondLen; + int tempErrno; if (firstPtr == secondPtr) { return 1; @@ -2325,7 +2326,7 @@ SetFsPathFromAny( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ Tcl_Obj *pathPtr) /* The object to convert. */ { - int len; + size_t len; FsPath *fsPathPtr; Tcl_Obj *transPtr; char *name; @@ -2356,7 +2357,7 @@ SetFsPathFromAny( if (name[0] == '~') { Tcl_DString temp; - int split; + size_t split; char separator = '/'; split = FindSplitPos(name, separator); @@ -2608,7 +2609,7 @@ UpdateStringOfFsPath( register Tcl_Obj *pathPtr) /* path obj with string rep to update. */ { FsPath *fsPathPtr = PATHOBJ(pathPtr); - int cwdLen; + size_t cwdLen; Tcl_Obj *copy; if (PATHFLAGS(pathPtr) == 0 || fsPathPtr->cwdPtr == NULL) { @@ -2676,7 +2677,7 @@ TclNativePathInFilesystem( * situation. */ - int len; + size_t len; (void) TclGetStringFromObj(pathPtr, &len); if (len == 0) { diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 786a0be..2b1f533 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -1731,7 +1731,7 @@ Tcl_AppendFormatToObj( if (Tcl_IsShared(appendObj)) { Tcl_Panic("%s called with shared object", "Tcl_AppendFormatToObj"); } - TclGetStringFromObj(appendObj, &originalLength); + (void)TclGetStringFromObj(appendObj, &originalLength); limit = INT_MAX - originalLength; /* @@ -2419,7 +2419,7 @@ Tcl_AppendFormatToObj( } } - TclGetStringFromObj(segment, &segmentNumBytes); + (void)TclGetStringFromObj(segment, &segmentNumBytes); if (segmentNumBytes > limit) { if (allocSegment) { Tcl_DecrRefCount(segment); diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 605595b..099bd63 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3314,15 +3314,14 @@ TclNeedSpace( *---------------------------------------------------------------------- */ -int +size_t TclFormatInt( char *buffer, /* Points to the storage into which the * formatted characters are written. */ Tcl_WideInt n) /* The integer to format. */ { - Tcl_WideInt intVal; - int i; - int numFormatted, j; + Tcl_WideInt intVal; + size_t i, numFormatted, j; const char *digits = "0123456789"; /* -- cgit v0.12