From 59eeb967a221a65eafeceea7460f438892396ef7 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 26 Dec 2018 15:04:16 +0000 Subject: Many internal int -> size_t increases, so string lengths > 2Gb can be handled correctly in many more places. --- generic/tclBinary.c | 15 +++-- generic/tclCmdMZ.c | 123 ++++++++++++++++++++------------------- generic/tclCompCmds.c | 11 ++-- generic/tclCompCmdsGR.c | 8 ++- generic/tclCompCmdsSZ.c | 40 +++++++------ generic/tclCompExpr.c | 4 +- generic/tclCompile.c | 2 +- generic/tclDictObj.c | 2 +- generic/tclDisassemble.c | 2 +- generic/tclEnsemble.c | 8 +-- generic/tclExecute.c | 142 +++++++++++++++++++++++----------------------- generic/tclFCmd.c | 2 +- generic/tclFileName.c | 9 +-- generic/tclIOCmd.c | 2 +- generic/tclIOUtil.c | 7 ++- generic/tclIndexObj.c | 6 +- generic/tclInt.decls | 2 +- generic/tclInt.h | 6 +- generic/tclIntDecls.h | 5 +- generic/tclListObj.c | 14 ++--- generic/tclMain.c | 2 +- generic/tclNamesp.c | 16 +++--- generic/tclOOCall.c | 2 +- generic/tclOODefineCmds.c | 10 ++-- generic/tclObj.c | 6 +- generic/tclParse.c | 2 +- generic/tclRegexp.c | 2 +- generic/tclStringObj.c | 21 +++---- generic/tclTestObj.c | 2 +- generic/tclUtil.c | 18 +++--- generic/tclZipfs.c | 4 +- unix/tclUnixFile.c | 2 +- win/tclWinPipe.c | 5 +- win/tclWinTest.c | 2 +- 34 files changed, 265 insertions(+), 239 deletions(-) diff --git a/generic/tclBinary.c b/generic/tclBinary.c index b270499..f3d648f 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -1111,7 +1111,7 @@ BinaryFormatCmd( case 'B': { unsigned char *last; - str = TclGetStringFromObj(objv[arg], &length); + str = Tcl_GetStringFromObj(objv[arg], &length); arg++; if (count == BINARY_ALL) { count = length; @@ -1173,7 +1173,7 @@ BinaryFormatCmd( unsigned char *last; int c; - str = TclGetStringFromObj(objv[arg], &length); + str = Tcl_GetStringFromObj(objv[arg], &length); arg++; if (count == BINARY_ALL) { count = length; @@ -2489,7 +2489,8 @@ BinaryDecodeHex( Tcl_Obj *resultObj = NULL; unsigned char *data, *datastart, *dataend; unsigned char *begin, *cursor, c; - int i, index, value, size, count = 0, cut = 0, strict = 0; + int i, index, value, size, cut = 0, strict = 0; + size_t count = 0; enum {OPT_STRICT }; static const char *const optStrings[] = { "-strict", NULL }; @@ -2609,7 +2610,7 @@ BinaryEncode64( unsigned char *data, *cursor, *limit; int maxlen = 0; const char *wrapchar = "\n"; - int wrapcharlen = 1; + size_t wrapcharlen = 1; int offset, i, index, size, outindex = 0, count = 0; enum {OPT_MAXLEN, OPT_WRAPCHAR }; static const char *const optStrings[] = { "-maxlen", "-wrapchar", NULL }; @@ -2830,7 +2831,8 @@ BinaryDecodeUu( Tcl_Obj *resultObj = NULL; unsigned char *data, *datastart, *dataend; unsigned char *begin, *cursor; - int i, index, size, count = 0, strict = 0, lineLen; + int i, index, size, strict = 0, lineLen; + size_t count = 0; unsigned char c; enum {OPT_STRICT }; static const char *const optStrings[] = { "-strict", NULL }; @@ -2995,7 +2997,8 @@ BinaryDecode64( unsigned char *begin = NULL; unsigned char *cursor = NULL; int strict = 0; - int i, index, size, cut = 0, count = 0; + int i, index, size, cut = 0; + size_t count = 0; enum { OPT_STRICT }; static const char *const optStrings[] = { "-strict", NULL }; diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 02eabe0..4b90cd5 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -194,7 +194,7 @@ Tcl_RegexpObjCmd( if (++i >= objc) { goto endOfForLoop; } - if (TclGetIntForIndexM(interp, objv[i], 0, &temp) != TCL_OK) { + if (TclGetIntForIndexM(interp, objv[i], TCL_INDEX_START, &temp) != TCL_OK) { goto optionError; } if (startIndex) { @@ -550,7 +550,7 @@ Tcl_RegsubObjCmd( if (++idx >= objc) { goto endOfForLoop; } - if (TclGetIntForIndexM(interp, objv[idx], 0, &temp) != TCL_OK) { + if (TclGetIntForIndexM(interp, objv[idx], TCL_INDEX_START, &temp) != TCL_OK) { goto optionError; } if (startIndex) { @@ -581,7 +581,7 @@ Tcl_RegsubObjCmd( objv += idx; if (startIndex) { - int stringLength = Tcl_GetCharLength(objv[1]); + size_t stringLength = Tcl_GetCharLength(objv[1]); TclGetIntForIndexM(interp, startIndex, stringLength, &offset); Tcl_DecrRefCount(startIndex); @@ -1332,9 +1332,9 @@ StringFirstCmd( } if (objc == 4) { - int size = Tcl_GetCharLength(objv[2]); + size_t end = Tcl_GetCharLength(objv[2]) - 1; - if (TCL_OK != TclGetIntForIndexM(interp, objv[3], size - 1, &start)) { + if (TCL_OK != TclGetIntForIndexM(interp, objv[3], end, &start)) { return TCL_ERROR; } } @@ -1380,9 +1380,9 @@ StringLastCmd( } if (objc == 4) { - int size = Tcl_GetCharLength(objv[2]); + size_t end = Tcl_GetCharLength(objv[2]) - 1; - if (TCL_OK != TclGetIntForIndexM(interp, objv[3], size - 1, &last)) { + if (TCL_OK != TclGetIntForIndexM(interp, objv[3], end, &last)) { return TCL_ERROR; } } @@ -1419,7 +1419,8 @@ StringIndexCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int length, index; + size_t end; + int index; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "string charIndex"); @@ -1430,12 +1431,12 @@ StringIndexCmd( * Get the char length to calculate what 'end' means. */ - length = Tcl_GetCharLength(objv[1]); - if (TclGetIntForIndexM(interp, objv[2], length-1, &index) != TCL_OK) { + end = Tcl_GetCharLength(objv[1]) - 1; + if (TclGetIntForIndexM(interp, objv[2], end, &index) != TCL_OK) { return TCL_ERROR; } - if ((index >= 0) && (index < length)) { + if ((index >= 0) && (index <= (int)end)) { int ch = Tcl_GetUniChar(objv[1], index); if (ch == -1) { @@ -1454,11 +1455,11 @@ StringIndexCmd( } else { char buf[4]; - length = Tcl_UniCharToUtf(ch, buf); - if (!length) { - length = Tcl_UniCharToUtf(-1, buf); + end = Tcl_UniCharToUtf(ch, buf); + if (!end) { + end = Tcl_UniCharToUtf(-1, buf); } - Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, length)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, end)); } } return TCL_OK; @@ -1492,7 +1493,8 @@ StringIsCmd( const char *string1, *end, *stop; Tcl_UniChar ch = 0; int (*chcomp)(int) = NULL; /* The UniChar comparison function. */ - int i, failat = 0, result = 1, strict = 0, index, length3; + int i, result = 1, strict = 0, index, length3; + size_t failat = 0; size_t length1, length2; Tcl_Obj *objPtr, *failVarObj = NULL; Tcl_WideInt w; @@ -1961,7 +1963,7 @@ StringMapCmd( * inconsistencies (see test string-10.20.1 for illustration why!) */ - if (!TclHasStringRep(objv[objc-2]) + if (!TclHasStringRep(objv[objc-2]) && Tcl_FetchIntRep(objv[objc-2], &tclDictType)){ int i, done; Tcl_DictSearch search; @@ -2255,7 +2257,7 @@ StringRangeCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - size_t length; + size_t end; int first, last; if (objc != 4) { @@ -2268,18 +2270,18 @@ StringRangeCmd( * 'end' refers to the last character, not one past it. */ - length = Tcl_GetCharLength(objv[1]) - 1; + end = Tcl_GetCharLength(objv[1]) - 1; - if (TclGetIntForIndexM(interp, objv[2], length, &first) != TCL_OK || - TclGetIntForIndexM(interp, objv[3], length, &last) != TCL_OK) { + if (TclGetIntForIndexM(interp, objv[2], end, &first) != TCL_OK || + TclGetIntForIndexM(interp, objv[3], end, &last) != TCL_OK) { return TCL_ERROR; } if (first < 0) { first = 0; } - if (last >= (int)length) { - last = length; + if (last >= (int)end) { + last = end; } if (last >= first) { Tcl_SetObjResult(interp, Tcl_GetRange(objv[1], first, last)); @@ -2368,15 +2370,15 @@ StringRplcCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int first, last, length, end; + int first, last; + size_t end; if (objc < 4 || objc > 5) { Tcl_WrongNumArgs(interp, 1, objv, "string first last ?string?"); return TCL_ERROR; } - length = Tcl_GetCharLength(objv[1]); - end = length - 1; + end = Tcl_GetCharLength(objv[1]) - 1; if (TclGetIntForIndexM(interp, objv[2], end, &first) != TCL_OK || TclGetIntForIndexM(interp, objv[3], end, &last) != TCL_OK){ @@ -2389,7 +2391,7 @@ StringRplcCmd( * replacement is done, and the result is the original string, */ if ((last < 0) || /* Range ends before start of string */ - (first > end) || /* Range begins after end of string */ + (first > (int)end) || /* Range begins after end of string */ (last < first)) { /* Range begins after it starts */ /* @@ -2404,7 +2406,7 @@ StringRplcCmd( if (first < 0) { first = 0; } - if (last > end) { + if (last > (int)end) { last = end; } @@ -2479,7 +2481,8 @@ StringStartCmd( { Tcl_UniChar ch = 0; const char *p, *string; - int cur, index, length, numChars; + int cur, index; + size_t numChars, length; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "string index"); @@ -2487,13 +2490,13 @@ StringStartCmd( } string = TclGetStringFromObj(objv[1], &length); - numChars = Tcl_NumUtfChars(string, length); - if (TclGetIntForIndexM(interp, objv[2], numChars-1, &index) != TCL_OK) { + numChars = Tcl_NumUtfChars(string, length) - 1; + if (TclGetIntForIndexM(interp, objv[2], numChars, &index) != TCL_OK) { return TCL_ERROR; } string = TclGetStringFromObj(objv[1], &length); - if (index >= numChars) { - index = numChars - 1; + if (index > (int)numChars) { + index = numChars; } cur = 0; if (index > 0) { @@ -2540,7 +2543,8 @@ StringEndCmd( { Tcl_UniChar ch = 0; const char *p, *end, *string; - int cur, index, length, numChars; + int cur, index; + size_t length, numChars; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "string index"); @@ -2548,15 +2552,15 @@ StringEndCmd( } string = TclGetStringFromObj(objv[1], &length); - numChars = Tcl_NumUtfChars(string, length); - if (TclGetIntForIndexM(interp, objv[2], numChars-1, &index) != TCL_OK) { + numChars = Tcl_NumUtfChars(string, length) - 1; + if (TclGetIntForIndexM(interp, objv[2], numChars, &index) != TCL_OK) { return TCL_ERROR; } string = TclGetStringFromObj(objv[1], &length); if (index < 0) { index = 0; } - if (index < numChars) { + if (index <= (int) numChars) { p = Tcl_UtfAtIndex(string, index); end = string+length; for (cur = index; p < end; cur++) { @@ -2569,7 +2573,7 @@ StringEndCmd( cur++; } } else { - cur = numChars; + cur = numChars + 1; } Tcl_SetObjResult(interp, Tcl_NewWideIntObj(cur)); return TCL_OK; @@ -2607,7 +2611,8 @@ StringEqualCmd( */ const char *string2; - int length, i, match, nocase = 0, reqlength = -1; + int i, match, nocase = 0, reqlength = -1; + size_t length; if (objc < 3 || objc > 6) { str_cmp_args: @@ -2618,10 +2623,10 @@ StringEqualCmd( for (i = 1; i < objc-2; i++) { string2 = TclGetStringFromObj(objv[i], &length); - if ((length > 1) && !strncmp(string2, "-nocase", (size_t)length)) { + if ((length > 1) && !strncmp(string2, "-nocase", length)) { nocase = 1; } else if ((length > 1) - && !strncmp(string2, "-length", (size_t)length)) { + && !strncmp(string2, "-length", length)) { if (i+1 >= objc-2) { goto str_cmp_args; } @@ -2702,7 +2707,8 @@ TclStringCmpOpts( int *nocase, int *reqlength) { - int i, length; + int i; + size_t length; const char *string; *reqlength = -1; @@ -2716,10 +2722,10 @@ TclStringCmpOpts( for (i = 1; i < objc-2; i++) { string = TclGetStringFromObj(objv[i], &length); - if ((length > 1) && !strncmp(string, "-nocase", (size_t)length)) { + if ((length > 1) && !strncmp(string, "-nocase", length)) { *nocase = 1; } else if ((length > 1) - && !strncmp(string, "-length", (size_t)length)) { + && !strncmp(string, "-length", length)) { if (i+1 >= objc-2) { goto str_cmp_args; } @@ -2809,7 +2815,7 @@ StringBytesCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int length; + size_t length; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "string"); @@ -2880,7 +2886,7 @@ StringLowerCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int length1, length2; + size_t length1, length2; const char *string1; char *string2; @@ -2916,7 +2922,7 @@ StringLowerCmd( return TCL_ERROR; } - if (last >= length1) { + if (last >= (int)length1) { last = length1; } if (last < first) { @@ -2965,7 +2971,7 @@ StringUpperCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int length1, length2; + size_t length1, length2; const char *string1; char *string2; @@ -3001,7 +3007,7 @@ StringUpperCmd( return TCL_ERROR; } - if (last >= length1) { + if (last >= (int)length1) { last = length1; } if (last < first) { @@ -3050,7 +3056,7 @@ StringTitleCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int length1, length2; + size_t length1, length2; const char *string1; char *string2; @@ -3086,7 +3092,7 @@ StringTitleCmd( return TCL_ERROR; } - if (last >= length1) { + if (last >= (int)length1) { last = length1; } if (last < first) { @@ -3183,7 +3189,8 @@ StringTrimLCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { const char *string1, *string2; - int trim, length1, length2; + int trim; + size_t length1, length2; if (objc == 3) { string2 = TclGetStringFromObj(objv[2], &length2); @@ -3229,7 +3236,8 @@ StringTrimRCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { const char *string1, *string2; - int trim, length1, length2; + int trim; + size_t length1, length2; if (objc == 3) { string2 = TclGetStringFromObj(objv[2], &length2); @@ -3428,7 +3436,8 @@ TclNRSwitchObjCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { int i,j, index, mode, foundmode, splitObjs, numMatchesSaved; - int noCase, patternLength; + int noCase; + size_t patternLength; const char *pattern; Tcl_Obj *stringObj, *indexVarObj, *matchVarObj; Tcl_Obj *const *savedObjv = objv; @@ -3892,7 +3901,7 @@ SwitchPostProc( CmdFrame *ctxPtr = data[1]; int pc = PTR2INT(data[2]); const char *pattern = data[3]; - int patternLength = strlen(pattern); + size_t patternLength = strlen(pattern); /* * Clean up TIP 280 context information @@ -3914,12 +3923,12 @@ SwitchPostProc( */ if (result == TCL_ERROR) { - int limit = 50; + unsigned limit = 50; int overflow = (patternLength > limit); Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf( "\n (\"%.*s%s\" arm line %d)", - (overflow ? limit : patternLength), pattern, + (overflow ? limit : (unsigned)patternLength), pattern, (overflow ? "..." : ""), Tcl_GetErrorLine(interp))); } TclStackFree(interp, ctxPtr); diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index 9429289..536180d 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -908,12 +908,13 @@ TclCompileConcatCmd( Tcl_Obj **objs; const char *bytes; int len; + size_t slen; Tcl_ListObjGetElements(NULL, listObj, &len, &objs); objPtr = Tcl_ConcatObj(len, objs); Tcl_DecrRefCount(listObj); - bytes = TclGetStringFromObj(objPtr, &len); - PushLiteral(envPtr, bytes, len); + bytes = TclGetStringFromObj(objPtr, &slen); + PushLiteral(envPtr, bytes, slen); Tcl_DecrRefCount(objPtr); return TCL_OK; } @@ -1281,7 +1282,8 @@ TclCompileDictCreateCmd( Tcl_Token *tokenPtr; Tcl_Obj *keyObj, *valueObj, *dictObj; const char *bytes; - int i, len; + int i; + size_t len; if ((parsePtr->numWords & 1) == 0) { return TCL_ERROR; @@ -3144,7 +3146,8 @@ TclCompileFormatCmd( Tcl_Token *tokenPtr = parsePtr->tokenPtr; Tcl_Obj **objv, *formatObj, *tmpObj; char *bytes, *start; - int i, j, len; + int i, j; + size_t len; /* * Don't handle any guaranteed-error cases. diff --git a/generic/tclCompCmdsGR.c b/generic/tclCompCmdsGR.c index a3bddd5..e9d6f5e 100644 --- a/generic/tclCompCmdsGR.c +++ b/generic/tclCompCmdsGR.c @@ -2270,7 +2270,8 @@ TclCompileRegsubCmd( Tcl_Obj *patternObj = NULL, *replacementObj = NULL; Tcl_DString pattern; const char *bytes; - int len, exact, quantified, result = TCL_ERROR; + int exact, quantified, result = TCL_ERROR; + size_t len; if (parsePtr->numWords < 5 || parsePtr->numWords > 6) { return TCL_ERROR; @@ -2348,7 +2349,7 @@ TclCompileRegsubCmd( */ len = Tcl_DStringLength(&pattern) - 2; - if (len > 0) { + if (len + 2 > 2) { goto isSimpleGlob; } @@ -2863,7 +2864,8 @@ IndexTailVarIfKnown( { Tcl_Obj *tailPtr; const char *tailName, *p; - int len, n = varTokenPtr->numComponents; + int n = varTokenPtr->numComponents; + size_t len; Tcl_Token *lastTokenPtr; int full, localIndex; diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c index 5af9081..ae33b33 100644 --- a/generic/tclCompCmdsSZ.c +++ b/generic/tclCompCmdsSZ.c @@ -259,7 +259,7 @@ TclCompileStringCatCmd( } else { Tcl_DecrRefCount(obj); if (folded) { - int len; + size_t len; const char *bytes = TclGetStringFromObj(folded, &len); PushLiteral(envPtr, bytes, len); @@ -277,7 +277,7 @@ TclCompileStringCatCmd( wordTokenPtr = TokenAfter(wordTokenPtr); } if (folded) { - int len; + size_t len; const char *bytes = TclGetStringFromObj(folded, &len); PushLiteral(envPtr, bytes, len); @@ -844,9 +844,9 @@ TclCompileStringLenCmd( */ char buf[TCL_INTEGER_SPACE]; - int len = Tcl_GetCharLength(objPtr); + size_t len = Tcl_GetCharLength(objPtr); - len = sprintf(buf, "%d", len); + len = sprintf(buf, "%" TCL_Z_MODIFIER "d", len); PushLiteral(envPtr, buf, len); } else { SetLineInformation(1); @@ -871,6 +871,7 @@ TclCompileStringMapCmd( Tcl_Obj *mapObj, **objv; char *bytes; int len; + size_t slen; /* * We only handle the case: @@ -906,13 +907,13 @@ TclCompileStringMapCmd( * correct semantics for mapping. */ - bytes = TclGetStringFromObj(objv[0], &len); - if (len == 0) { + bytes = TclGetStringFromObj(objv[0], &slen); + if (slen == 0) { CompileWord(envPtr, stringTokenPtr, interp, 2); } else { - PushLiteral(envPtr, bytes, len); - bytes = TclGetStringFromObj(objv[1], &len); - PushLiteral(envPtr, bytes, len); + PushLiteral(envPtr, bytes, slen); + bytes = TclGetStringFromObj(objv[1], &slen); + PushLiteral(envPtr, bytes, slen); CompileWord(envPtr, stringTokenPtr, interp, 2); OP(STR_MAP); } @@ -1505,7 +1506,8 @@ TclSubstCompile( for (endTokenPtr = tokenPtr + parse.numTokens; tokenPtr < endTokenPtr; tokenPtr = TokenAfter(tokenPtr)) { - int length, literal, catchRange, breakJump; + size_t length; + int literal, catchRange, breakJump; char buf[TCL_UTF_MAX]; JumpFixup startFixup, okFixup, returnFixup, breakFixup; JumpFixup continueFixup, otherFixup, endFixup; @@ -1536,7 +1538,7 @@ TclSubstCompile( */ if (tokenPtr->numComponents > 1) { - size_t i; + size_t i; int foundCommand = 0; for (i=2 ; i<=tokenPtr->numComponents ; i++) { @@ -2881,7 +2883,7 @@ TclCompileTryCmd( goto failedToCompile; } if (objc > 0) { - int len; + size_t len; const char *varname = TclGetStringFromObj(objv[0], &len); resultVarIndices[i] = LocalScalar(varname, len, envPtr); @@ -2893,7 +2895,7 @@ TclCompileTryCmd( resultVarIndices[i] = -1; } if (objc == 2) { - int len; + size_t len; const char *varname = TclGetStringFromObj(objv[1], &len); optionVarIndices[i] = LocalScalar(varname, len, envPtr); @@ -3012,6 +3014,7 @@ IssueTryClausesInstructions( DefineLineInformation; /* TIP #280 */ int range, resultVar, optionsVar; int i, j, len, forwardsNeedFixing = 0, trapZero = 0, afterBody = 0; + size_t slen; int *addrsToFix, *forwardsToFix, notCodeJumpSource, notECJumpSource; int *noError; char buf[TCL_INTEGER_SPACE]; @@ -3097,8 +3100,8 @@ IssueTryClausesInstructions( OP4( DICT_GET, 1); TclAdjustStackDepth(-1, envPtr); OP44( LIST_RANGE_IMM, 0, len-1); - p = TclGetStringFromObj(matchClauses[i], &len); - PushLiteral(envPtr, p, len); + p = TclGetStringFromObj(matchClauses[i], &slen); + PushLiteral(envPtr, p, slen); OP( STR_EQ); JUMP4( JUMP_FALSE, notECJumpSource); } else { @@ -3225,6 +3228,7 @@ IssueTryClausesFinallyInstructions( int trapZero = 0, afterBody = 0, finalOK, finalError, noFinalError; int *addrsToFix, *forwardsToFix, notCodeJumpSource, notECJumpSource; char buf[TCL_INTEGER_SPACE]; + size_t slen; resultVar = AnonymousLocal(envPtr); optionsVar = AnonymousLocal(envPtr); @@ -3308,8 +3312,8 @@ IssueTryClausesFinallyInstructions( OP4( DICT_GET, 1); TclAdjustStackDepth(-1, envPtr); OP44( LIST_RANGE_IMM, 0, len-1); - p = TclGetStringFromObj(matchClauses[i], &len); - PushLiteral(envPtr, p, len); + p = TclGetStringFromObj(matchClauses[i], &slen); + PushLiteral(envPtr, p, slen); OP( STR_EQ); JUMP4( JUMP_FALSE, notECJumpSource); } else { @@ -3634,7 +3638,7 @@ TclCompileUnsetCmd( } if (varCount == 0) { const char *bytes; - int len; + size_t len; bytes = TclGetStringFromObj(leadingWord, &len); if (i == 1 && len == 11 && !strncmp("-nocomplain", bytes, 11)) { diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c index 057af2b..c67a56f 100644 --- a/generic/tclCompExpr.c +++ b/generic/tclCompExpr.c @@ -2260,7 +2260,7 @@ CompileExprTree( case FUNCTION: { Tcl_DString cmdName; const char *p; - int length; + size_t length; Tcl_DStringInit(&cmdName); TclDStringAppendLiteral(&cmdName, "tcl::mathfunc::"); @@ -2419,7 +2419,7 @@ CompileExprTree( Tcl_Obj *literal = *litObjv; if (optimize) { - int length; + size_t length; const char *bytes = TclGetStringFromObj(literal, &length); int index = TclRegisterLiteral(envPtr, bytes, length, 0); Tcl_Obj *objPtr = TclFetchLiteral(envPtr, index); diff --git a/generic/tclCompile.c b/generic/tclCompile.c index 2e1ad67..cbdf373 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -1727,7 +1727,7 @@ TclWordKnownAtCompileTime( case TCL_TOKEN_BS: if (tempPtr != NULL) { char utfBuf[TCL_UTF_MAX]; - int length = TclParseBackslash(tokenPtr->start, + size_t length = TclParseBackslash(tokenPtr->start, tokenPtr->size, NULL, utfBuf); Tcl_AppendToObj(tempPtr, utfBuf, length); diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c index 305a678..3875967 100644 --- a/generic/tclDictObj.c +++ b/generic/tclDictObj.c @@ -648,7 +648,7 @@ SetDictFromAny( Tcl_IncrRefCount(objv[i+1]); /* Since hash now holds ref to it */ } } else { - int length; + size_t length; const char *nextElem = TclGetStringFromObj(objPtr, &length); const char *limit = (nextElem + length); diff --git a/generic/tclDisassemble.c b/generic/tclDisassemble.c index 2cd9ca9..c36412d 100644 --- a/generic/tclDisassemble.c +++ b/generic/tclDisassemble.c @@ -653,7 +653,7 @@ FormatInstruction( } if (suffixObj) { const char *bytes; - int length; + size_t length; Tcl_AppendToObj(bufferObj, "\t# ", -1); bytes = TclGetStringFromObj(codePtr->objArrayPtr[opnd], &length); diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index 3050ca9..c92a68c 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -2911,7 +2911,7 @@ TclCompileEnsemble( Command *oldCmdPtr = cmdPtr, *newCmdPtr; int len, result, flags = 0, i, depth = 1, invokeAnyway = 0; int ourResult = TCL_ERROR; - unsigned numBytes; + size_t numBytes; const char *word; DefineLineInformation; @@ -2981,7 +2981,7 @@ TclCompileEnsemble( (void) Tcl_GetEnsembleSubcommandList(NULL, ensemble, &listObj); if (listObj != NULL) { - int sclen; + size_t sclen; const char *str; Tcl_Obj *matchObj = NULL; @@ -2990,7 +2990,7 @@ TclCompileEnsemble( } for (i=0 ; ivarFramePtr->nsPtr; @@ -4932,24 +4932,24 @@ TEBCresume( case INST_STR_LEN: valuePtr = OBJ_AT_TOS; - length = Tcl_GetCharLength(valuePtr); - TclNewIntObj(objResultPtr, length); - TRACE(("\"%.20s\" => %d\n", O2S(valuePtr), length)); + slength = Tcl_GetCharLength(valuePtr); + TclNewIntObj(objResultPtr, slength); + TRACE(("\"%.20s\" => %" TCL_Z_MODIFIER "d\n", O2S(valuePtr), slength)); NEXT_INST_F(1, 1, 1); case INST_STR_UPPER: valuePtr = OBJ_AT_TOS; TRACE(("\"%.20s\" => ", O2S(valuePtr))); if (Tcl_IsShared(valuePtr)) { - s1 = TclGetStringFromObj(valuePtr, &length); - TclNewStringObj(objResultPtr, s1, length); - length = Tcl_UtfToUpper(TclGetString(objResultPtr)); - Tcl_SetObjLength(objResultPtr, length); + s1 = TclGetStringFromObj(valuePtr, &slength); + TclNewStringObj(objResultPtr, s1, slength); + slength = Tcl_UtfToUpper(TclGetString(objResultPtr)); + Tcl_SetObjLength(objResultPtr, slength); TRACE_APPEND(("\"%.20s\"\n", O2S(objResultPtr))); NEXT_INST_F(1, 1, 1); } else { - length = Tcl_UtfToUpper(TclGetString(valuePtr)); - Tcl_SetObjLength(valuePtr, length); + slength = Tcl_UtfToUpper(TclGetString(valuePtr)); + Tcl_SetObjLength(valuePtr, slength); TclFreeIntRep(valuePtr); TRACE_APPEND(("\"%.20s\"\n", O2S(valuePtr))); NEXT_INST_F(1, 0, 0); @@ -4958,15 +4958,15 @@ TEBCresume( valuePtr = OBJ_AT_TOS; TRACE(("\"%.20s\" => ", O2S(valuePtr))); if (Tcl_IsShared(valuePtr)) { - s1 = TclGetStringFromObj(valuePtr, &length); - TclNewStringObj(objResultPtr, s1, length); - length = Tcl_UtfToLower(TclGetString(objResultPtr)); - Tcl_SetObjLength(objResultPtr, length); + s1 = TclGetStringFromObj(valuePtr, &slength); + TclNewStringObj(objResultPtr, s1, slength); + slength = Tcl_UtfToLower(TclGetString(objResultPtr)); + Tcl_SetObjLength(objResultPtr, slength); TRACE_APPEND(("\"%.20s\"\n", O2S(objResultPtr))); NEXT_INST_F(1, 1, 1); } else { - length = Tcl_UtfToLower(TclGetString(valuePtr)); - Tcl_SetObjLength(valuePtr, length); + slength = Tcl_UtfToLower(TclGetString(valuePtr)); + Tcl_SetObjLength(valuePtr, slength); TclFreeIntRep(valuePtr); TRACE_APPEND(("\"%.20s\"\n", O2S(valuePtr))); NEXT_INST_F(1, 0, 0); @@ -4975,15 +4975,15 @@ TEBCresume( valuePtr = OBJ_AT_TOS; TRACE(("\"%.20s\" => ", O2S(valuePtr))); if (Tcl_IsShared(valuePtr)) { - s1 = TclGetStringFromObj(valuePtr, &length); - TclNewStringObj(objResultPtr, s1, length); - length = Tcl_UtfToTitle(TclGetString(objResultPtr)); - Tcl_SetObjLength(objResultPtr, length); + s1 = TclGetStringFromObj(valuePtr, &slength); + TclNewStringObj(objResultPtr, s1, slength); + slength = Tcl_UtfToTitle(TclGetString(objResultPtr)); + Tcl_SetObjLength(objResultPtr, slength); TRACE_APPEND(("\"%.20s\"\n", O2S(objResultPtr))); NEXT_INST_F(1, 1, 1); } else { - length = Tcl_UtfToTitle(TclGetString(valuePtr)); - Tcl_SetObjLength(valuePtr, length); + slength = Tcl_UtfToTitle(TclGetString(valuePtr)); + Tcl_SetObjLength(valuePtr, slength); TclFreeIntRep(valuePtr); TRACE_APPEND(("\"%.20s\"\n", O2S(valuePtr))); NEXT_INST_F(1, 0, 0); @@ -4998,18 +4998,18 @@ TEBCresume( * Get char length to calulate what 'end' means. */ - length = Tcl_GetCharLength(valuePtr); - if (TclGetIntForIndexM(interp, value2Ptr, length-1, &index)!=TCL_OK) { + slength = Tcl_GetCharLength(valuePtr); + if (TclGetIntForIndexM(interp, value2Ptr, slength-1, &index)!=TCL_OK) { TRACE_ERROR(interp); goto gotError; } - if ((index < 0) || (index >= length)) { + if ((index < 0) || (index >= (int)slength)) { TclNewObj(objResultPtr); } else if (TclIsPureByteArray(valuePtr)) { objResultPtr = Tcl_NewByteArrayObj( Tcl_GetByteArrayFromObj(valuePtr, NULL)+index, 1); - } else if (valuePtr->bytes && (size_t)length == valuePtr->length) { + } else if (valuePtr->bytes && slength == valuePtr->length) { objResultPtr = Tcl_NewStringObj((const char *) valuePtr->bytes+index, 1); } else { @@ -5024,11 +5024,11 @@ TEBCresume( if (ch == -1) { objResultPtr = Tcl_NewObj(); } else { - length = Tcl_UniCharToUtf(ch, buf); - if (!length) { - length = Tcl_UniCharToUtf(-1, buf); + slength = Tcl_UniCharToUtf(ch, buf); + if (!slength) { + slength = Tcl_UniCharToUtf(-1, buf); } - objResultPtr = Tcl_NewStringObj(buf, length); + objResultPtr = Tcl_NewStringObj(buf, slength); } } @@ -5038,10 +5038,10 @@ TEBCresume( case INST_STR_RANGE: TRACE(("\"%.20s\" %.20s %.20s =>", O2S(OBJ_AT_DEPTH(2)), O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS))); - length = Tcl_GetCharLength(OBJ_AT_DEPTH(2)) - 1; - if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, length, + slength = Tcl_GetCharLength(OBJ_AT_DEPTH(2)) - 1; + if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, slength, &fromIdx) != TCL_OK - || TclGetIntForIndexM(interp, OBJ_AT_TOS, length, + || TclGetIntForIndexM(interp, OBJ_AT_TOS, slength, &toIdx) != TCL_OK) { TRACE_ERROR(interp); goto gotError; @@ -5050,8 +5050,8 @@ TEBCresume( if (fromIdx < 0) { fromIdx = 0; } - if (toIdx >= length) { - toIdx = length; + if (toIdx >= (int)slength) { + toIdx = slength; } if (toIdx >= fromIdx) { objResultPtr = Tcl_GetRange(OBJ_AT_DEPTH(2), fromIdx, toIdx); @@ -5065,11 +5065,11 @@ TEBCresume( valuePtr = OBJ_AT_TOS; fromIdx = TclGetInt4AtPtr(pc+1); toIdx = TclGetInt4AtPtr(pc+5); - length = Tcl_GetCharLength(valuePtr); + slength = Tcl_GetCharLength(valuePtr); TRACE(("\"%.20s\" %d %d => ", O2S(valuePtr), fromIdx, toIdx)); /* Every range of an empty value is an empty value */ - if (length == 0) { + if (slength == 0) { TRACE_APPEND(("\n")); NEXT_INST_F(9, 0, 0); } @@ -5089,14 +5089,14 @@ TEBCresume( toIdx = TCL_INDEX_END; } - toIdx = TclIndexDecode(toIdx, length - 1); + toIdx = TclIndexDecode(toIdx, slength - 1); if (toIdx < 0) { goto emptyRange; - } else if (toIdx >= length) { - toIdx = length - 1; + } else if (toIdx >= (int)slength) { + toIdx = slength - 1; } - assert ( toIdx >= 0 && toIdx < length ); + assert ( toIdx >= 0 && toIdx < slength ); /* assert ( fromIdx != TCL_INDEX_BEFORE ); @@ -5111,7 +5111,7 @@ TEBCresume( goto emptyRange; } - fromIdx = TclIndexDecode(fromIdx, length - 1); + fromIdx = TclIndexDecode(fromIdx, slength - 1); if (fromIdx < 0) { fromIdx = 0; } @@ -5127,18 +5127,18 @@ TEBCresume( { Tcl_UniChar *ustring1, *ustring2, *ustring3, *end, *p; - int length3, endIdx; + int length3; Tcl_Obj *value3Ptr; case INST_STR_REPLACE: value3Ptr = POP_OBJECT(); valuePtr = OBJ_AT_DEPTH(2); - endIdx = Tcl_GetCharLength(valuePtr) - 1; + slength = Tcl_GetCharLength(valuePtr) - 1; TRACE(("\"%.20s\" %s %s \"%.20s\" => ", O2S(valuePtr), O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS), O2S(value3Ptr))); - if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, endIdx, + if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, slength, &fromIdx) != TCL_OK - || TclGetIntForIndexM(interp, OBJ_AT_TOS, endIdx, + || TclGetIntForIndexM(interp, OBJ_AT_TOS, slength, &toIdx) != TCL_OK) { TclDecrRefCount(value3Ptr); TRACE_ERROR(interp); @@ -5150,7 +5150,7 @@ TEBCresume( (void) POP_OBJECT(); if ((toIdx < 0) || - (fromIdx > endIdx) || + (fromIdx > (int)slength) || (toIdx < fromIdx)) { TRACE_APPEND(("\"%.30s\"\n", O2S(valuePtr))); TclDecrRefCount(value3Ptr); @@ -5161,11 +5161,11 @@ TEBCresume( fromIdx = 0; } - if (toIdx > endIdx) { - toIdx = endIdx; + if (toIdx > (int)slength) { + toIdx = slength; } - if (fromIdx == 0 && toIdx == endIdx) { + if (fromIdx == 0 && toIdx == (int)slength) { TclDecrRefCount(OBJ_AT_TOS); OBJ_AT_TOS = value3Ptr; TRACE_APPEND(("\"%.30s\"\n", O2S(value3Ptr))); @@ -5197,28 +5197,28 @@ TEBCresume( objResultPtr = value3Ptr; goto doneStringMap; } - ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &length); - if (length == 0) { + ustring1 = TclGetUnicodeFromObj(valuePtr, &slength); + if (slength == 0) { objResultPtr = valuePtr; goto doneStringMap; } - ustring2 = Tcl_GetUnicodeFromObj(value2Ptr, &length2); - if (length2 > length || length2 == 0) { + ustring2 = TclGetUnicodeFromObj(value2Ptr, &length2); + if (length2 > (int)slength || length2 == 0) { objResultPtr = valuePtr; goto doneStringMap; - } else if (length2 == length) { - if (memcmp(ustring1, ustring2, sizeof(Tcl_UniChar) * length)) { + } else if (length2 == (int)slength) { + if (memcmp(ustring1, ustring2, sizeof(Tcl_UniChar) * slength)) { objResultPtr = valuePtr; } else { objResultPtr = value3Ptr; } goto doneStringMap; } - ustring3 = Tcl_GetUnicodeFromObj(value3Ptr, &length3); + ustring3 = TclGetUnicodeFromObj(value3Ptr, &length3); objResultPtr = Tcl_NewUnicodeObj(ustring1, 0); p = ustring1; - end = ustring1 + length; + end = ustring1 + slength; for (; ustring1 < end; ustring1++) { if ((*ustring1 == *ustring2) && (length2==1 || memcmp(ustring1, ustring2, sizeof(Tcl_UniChar) * length2) @@ -5267,10 +5267,10 @@ TEBCresume( valuePtr = OBJ_AT_TOS; TRACE(("%s \"%.30s\" => ", tclStringClassTable[opnd].name, O2S(valuePtr))); - ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &length); + ustring1 = TclGetUnicodeFromObj(valuePtr, &slength); match = 1; - if (length > 0) { - end = ustring1 + length; + if (slength > 0) { + end = ustring1 + slength; for (p=ustring1 ; ptypePtr == &tclStringType)) { Tcl_UniChar *ustring1, *ustring2; - ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &length); - ustring2 = Tcl_GetUnicodeFromObj(value2Ptr, &length2); - match = TclUniCharMatch(ustring1, length, ustring2, length2, + ustring1 = TclGetUnicodeFromObj(valuePtr, &slength); + ustring2 = TclGetUnicodeFromObj(value2Ptr, &length2); + match = TclUniCharMatch(ustring1, slength, ustring2, length2, nocase); } else if (TclIsPureByteArray(valuePtr) && !nocase) { unsigned char *bytes1, *bytes2; @@ -5333,24 +5333,24 @@ TEBCresume( valuePtr = OBJ_UNDER_TOS; /* String */ value2Ptr = OBJ_AT_TOS; /* TrimSet */ string2 = TclGetStringFromObj(value2Ptr, &length2); - string1 = TclGetStringFromObj(valuePtr, &length); - trim1 = TclTrimLeft(string1, length, string2, length2); + string1 = TclGetStringFromObj(valuePtr, &slength); + trim1 = TclTrimLeft(string1, slength, string2, length2); trim2 = 0; goto createTrimmedString; case INST_STR_TRIM_RIGHT: valuePtr = OBJ_UNDER_TOS; /* String */ value2Ptr = OBJ_AT_TOS; /* TrimSet */ string2 = TclGetStringFromObj(value2Ptr, &length2); - string1 = TclGetStringFromObj(valuePtr, &length); - trim2 = TclTrimRight(string1, length, string2, length2); + string1 = TclGetStringFromObj(valuePtr, &slength); + trim2 = TclTrimRight(string1, slength, string2, length2); trim1 = 0; goto createTrimmedString; case INST_STR_TRIM: valuePtr = OBJ_UNDER_TOS; /* String */ value2Ptr = OBJ_AT_TOS; /* TrimSet */ string2 = TclGetStringFromObj(value2Ptr, &length2); - string1 = TclGetStringFromObj(valuePtr, &length); - trim1 = TclTrim(string1, length, string2, length2, &trim2); + string1 = TclGetStringFromObj(valuePtr, &slength); + trim1 = TclTrim(string1, slength, string2, length2, &trim2); createTrimmedString: /* * Careful here; trim set often contains non-ASCII characters so we @@ -5373,7 +5373,7 @@ TEBCresume( #endif NEXT_INST_F(1, 1, 0); } else { - objResultPtr = Tcl_NewStringObj(string1+trim1, length-trim1-trim2); + objResultPtr = Tcl_NewStringObj(string1+trim1, slength-trim1-trim2); #ifdef TCL_COMPILE_DEBUG if (traceInstructions) { TclPrintObject(stdout, objResultPtr, 30); diff --git a/generic/tclFCmd.c b/generic/tclFCmd.c index a4dded2..5c6883d 100644 --- a/generic/tclFCmd.c +++ b/generic/tclFCmd.c @@ -1389,7 +1389,7 @@ TclFileTemporaryCmd( TclNewObj(nameObj); } if (objc > 2) { - int length; + size_t length; Tcl_Obj *templateObj = objv[2]; const char *string = TclGetStringFromObj(templateObj, &length); diff --git a/generic/tclFileName.c b/generic/tclFileName.c index 9f6b05b..f7d1e76 100644 --- a/generic/tclFileName.c +++ b/generic/tclFileName.c @@ -642,7 +642,7 @@ static Tcl_Obj * SplitUnixPath( const char *path) /* Pointer to string containing a path. */ { - int length; + size_t length; const char *origPath = path, *elementStart; Tcl_Obj *result = Tcl_NewObj(); @@ -731,7 +731,7 @@ static Tcl_Obj * SplitWinPath( const char *path) /* Pointer to string containing a path. */ { - int length; + size_t length; const char *p, *elementStart; Tcl_PathType type = TCL_PATH_ABSOLUTE; Tcl_DString buf; @@ -852,7 +852,8 @@ TclpNativeJoinPath( Tcl_Obj *prefix, const char *joining) { - int length, needsSep; + int needsSep; + size_t length; char *dest; const char *p; const char *start; @@ -2381,7 +2382,7 @@ DoGlob( */ if (*p == '\0') { - int length; + size_t length; Tcl_DString append; /* diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index a71966a..3e65002 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -462,7 +462,7 @@ Tcl_ReadObjCmd( if ((charactersRead > 0) && (newline != 0)) { const char *result; - int length; + size_t length; result = TclGetStringFromObj(resultPtr, &length); if (result[length - 1] == '\n') { diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index 07a36db..3a6233a 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -1752,7 +1752,8 @@ Tcl_FSEvalFileEx( const char *encodingName) /* If non-NULL, then use this encoding for the * file. NULL means use the system encoding. */ { - int length, result = TCL_ERROR; + size_t length; + int result = TCL_ERROR; Tcl_StatBuf statBuf; Tcl_Obj *oldScriptFile; Interp *iPtr; @@ -1866,12 +1867,12 @@ Tcl_FSEvalFileEx( */ const char *pathString = TclGetStringFromObj(pathPtr, &length); - int limit = 150; + unsigned limit = 150; int overflow = (length > limit); Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf( "\n (file \"%.*s%s\" line %d)", - (overflow ? limit : length), pathString, + (overflow ? limit : (unsigned)length), pathString, (overflow ? "..." : ""), Tcl_GetErrorLine(interp))); } diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index 4897de6..db267de 100644 --- a/generic/tclIndexObj.c +++ b/generic/tclIndexObj.c @@ -1027,7 +1027,7 @@ Tcl_ParseArgsObjv( * being processed, primarily for error * reporting. */ int objc; /* # arguments in objv still to process. */ - int length; /* Number of characters in current argument */ + size_t length; /* Number of characters in current argument */ if (remObjv != NULL) { /* @@ -1279,13 +1279,13 @@ PrintUsage( width = 4; for (infoPtr = argTable; infoPtr->type != TCL_ARGV_END; infoPtr++) { - int length; + size_t length; if (infoPtr->keyStr == NULL) { continue; } length = strlen(infoPtr->keyStr); - if (length > width) { + if (length > (size_t)width) { width = length; } } diff --git a/generic/tclInt.decls b/generic/tclInt.decls index af7602e..03f56c3 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -154,7 +154,7 @@ declare 32 { #} declare 34 { int TclGetIntForIndex(Tcl_Interp *interp, Tcl_Obj *objPtr, - int endValue, int *indexPtr) + size_t endValue, int *indexPtr) } # Removed in 8.4b2: #declare 35 { diff --git a/generic/tclInt.h b/generic/tclInt.h index 6c68147..e9de2c3 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3125,7 +3125,7 @@ MODULE_SCOPE void TclRememberJoinableThread(Tcl_ThreadId id); MODULE_SCOPE void TclRememberMutex(Tcl_Mutex *mutex); MODULE_SCOPE void TclRemoveScriptLimitCallbacks(Tcl_Interp *interp); MODULE_SCOPE int TclReToGlob(Tcl_Interp *interp, const char *reStr, - int reStrLen, Tcl_DString *dsPtr, int *flagsPtr, + size_t reStrLen, Tcl_DString *dsPtr, int *flagsPtr, int *quantifiersFoundPtr); MODULE_SCOPE size_t TclScanElement(const char *string, size_t length, char *flagPtr); @@ -4094,8 +4094,8 @@ MODULE_SCOPE Tcl_Obj * TclGetArrayDefault(Var *arrayPtr); */ MODULE_SCOPE int TclIndexEncode(Tcl_Interp *interp, Tcl_Obj *objPtr, - int before, int after, int *indexPtr); -MODULE_SCOPE int TclIndexDecode(int encoded, int endValue); + size_t before, size_t after, int *indexPtr); +MODULE_SCOPE int TclIndexDecode(int encoded, size_t endValue); /* Constants used in index value encoding routines. */ #define TCL_INDEX_END (-2) diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h index dcf9035..aa2ce34 100644 --- a/generic/tclIntDecls.h +++ b/generic/tclIntDecls.h @@ -111,7 +111,8 @@ EXTERN int TclGetFrame(Tcl_Interp *interp, const char *str, /* Slot 33 is reserved */ /* 34 */ EXTERN int TclGetIntForIndex(Tcl_Interp *interp, - Tcl_Obj *objPtr, int endValue, int *indexPtr); + Tcl_Obj *objPtr, size_t endValue, + int *indexPtr); /* Slot 35 is reserved */ /* Slot 36 is reserved */ /* 37 */ @@ -622,7 +623,7 @@ typedef struct TclIntStubs { const char * (*tclGetExtension) (const char *name); /* 31 */ int (*tclGetFrame) (Tcl_Interp *interp, const char *str, CallFrame **framePtrPtr); /* 32 */ void (*reserved33)(void); - int (*tclGetIntForIndex) (Tcl_Interp *interp, Tcl_Obj *objPtr, int endValue, int *indexPtr); /* 34 */ + int (*tclGetIntForIndex) (Tcl_Interp *interp, Tcl_Obj *objPtr, size_t endValue, int *indexPtr); /* 34 */ void (*reserved35)(void); void (*reserved36)(void); int (*tclGetLoadedPackages) (Tcl_Interp *interp, const char *targetName); /* 37 */ diff --git a/generic/tclListObj.c b/generic/tclListObj.c index b6fffcd..e5a8a55 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -966,9 +966,9 @@ Tcl_ListObjReplace( ListGetIntRep(listPtr, listRepPtr); if (listRepPtr == NULL) { - int length; + size_t length; - (void) Tcl_GetStringFromObj(listPtr, &length); + (void) TclGetStringFromObj(listPtr, &length); if (length == 0) { if (objc == 0) { return TCL_OK; @@ -1241,7 +1241,7 @@ TclLindexList( ListGetIntRep(argPtr, listRepPtr); if ((listRepPtr == NULL) - && TclGetIntForIndexM(NULL , argPtr, 0, &index) == TCL_OK) { + && TclGetIntForIndexM(NULL , argPtr, TCL_INDEX_START, &index) == TCL_OK) { /* * argPtr designates a single index. */ @@ -1346,7 +1346,7 @@ TclLindexFlat( */ while (++i < indexCount) { - if (TclGetIntForIndexM(interp, indexArray[i], -1, &index) + if (TclGetIntForIndexM(interp, indexArray[i], TCL_INDEX_BEFORE, &index) != TCL_OK) { Tcl_DecrRefCount(sublistCopy); return NULL; @@ -1410,7 +1410,7 @@ TclLsetList( ListGetIntRep(indexArgPtr, listRepPtr); if (listRepPtr == NULL - && TclGetIntForIndexM(NULL, indexArgPtr, 0, &index) == TCL_OK) { + && TclGetIntForIndexM(NULL, indexArgPtr, TCL_INDEX_START, &index) == TCL_OK) { /* * indexArgPtr designates a single index. */ @@ -1658,7 +1658,7 @@ TclLsetFlat( irPtr = Tcl_FetchIntRep(objPtr, &tclListType); listRepPtr = irPtr->twoPtrValue.ptr1; chainPtr = irPtr->twoPtrValue.ptr2; - + if (result == TCL_OK) { /* @@ -1883,7 +1883,7 @@ TclListObjSetElement( * a list object. * * Effect - * + * * Frees listPtr's List* internal representation, if no longer shared. * May decrement the ref counts of element objects, which may free them. * diff --git a/generic/tclMain.c b/generic/tclMain.c index 89c9034..ed04ce7 100644 --- a/generic/tclMain.c +++ b/generic/tclMain.c @@ -65,7 +65,7 @@ static inline Tcl_Obj * NewNativeObj( char *string, - int length) + size_t length) { Tcl_DString ds; diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index 954d98a..60e2af4 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -1231,7 +1231,7 @@ TclTeardownNamespace( #else if (nsPtr->childTablePtr != NULL) { while (nsPtr->childTablePtr->numEntries > 0) { - int length = nsPtr->childTablePtr->numEntries; + size_t length = nsPtr->childTablePtr->numEntries; Namespace **children = TclStackAlloc((Tcl_Interp *) iPtr, sizeof(Namespace *) * length); @@ -3049,7 +3049,7 @@ NamespaceChildrenCmd( listPtr = Tcl_NewListObj(0, NULL); if ((pattern != NULL) && TclMatchIsTrivial(pattern)) { - unsigned int length = strlen(nsPtr->fullName); + size_t length = strlen(nsPtr->fullName); if (strncmp(pattern, nsPtr->fullName, length) != 0) { goto searchDone; @@ -3129,7 +3129,7 @@ NamespaceCodeCmd( Namespace *currNsPtr; Tcl_Obj *listPtr, *objPtr; register const char *arg; - int length; + size_t length; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "arg"); @@ -3442,15 +3442,15 @@ NsEval_Callback( Tcl_Namespace *namespacePtr = data[0]; if (result == TCL_ERROR) { - int length = strlen(namespacePtr->fullName); - int limit = 200; + size_t length = strlen(namespacePtr->fullName); + unsigned limit = 200; int overflow = (length > limit); char *cmd = data[1]; Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf( "\n (in namespace %s \"%.*s%s\" script line %d)", cmd, - (overflow ? limit : length), namespacePtr->fullName, + (overflow ? limit : (unsigned)length), namespacePtr->fullName, (overflow ? "..." : ""), Tcl_GetErrorLine(interp))); } @@ -4249,7 +4249,7 @@ NamespaceQualifiersCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { register const char *name, *p; - int length; + size_t length; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "string"); @@ -4713,7 +4713,7 @@ FreeNsNameInternalRep( NsNameGetIntRep(objPtr, resNamePtr); assert(resNamePtr != NULL); - + /* * Decrement the reference count of the namespace. If there are no more * references, free it up. diff --git a/generic/tclOOCall.c b/generic/tclOOCall.c index e6a8ca0..c50f72f 100644 --- a/generic/tclOOCall.c +++ b/generic/tclOOCall.c @@ -1994,7 +1994,7 @@ AddSimpleClassDefineNamespaces( } else { AddDefinitionNamespaceToChain(classPtr, classPtr->objDefinitionNs, definePtr, flags); - } + } switch (classPtr->superclasses.num) { case 1: diff --git a/generic/tclOODefineCmds.c b/generic/tclOODefineCmds.c index 965badf..6caaa81 100644 --- a/generic/tclOODefineCmds.c +++ b/generic/tclOODefineCmds.c @@ -981,16 +981,16 @@ GenerateErrorInfo( * an object, class or class-as-object that * was being configured. */ { - int length; + size_t length; Tcl_Obj *realNameObj = Tcl_ObjectDeleted((Tcl_Object) oPtr) ? savedNameObj : TclOOObjectName(interp, oPtr); const char *objName = TclGetStringFromObj(realNameObj, &length); - int limit = OBJNAME_LENGTH_IN_ERRORINFO_LIMIT; + unsigned limit = OBJNAME_LENGTH_IN_ERRORINFO_LIMIT; int overflow = (length > limit); Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf( "\n (in definition script for %s \"%.*s%s\" line %d)", - typeOfSubject, (overflow ? limit : length), objName, + typeOfSubject, (overflow ? limit : (unsigned)length), objName, (overflow ? "..." : ""), Tcl_GetErrorLine(interp))); } @@ -1605,7 +1605,7 @@ TclOODefineDefnNsObjCmd( "may not modify the definition namespace of the root classes", -1)); Tcl_SetErrorCode(interp, "TCL", "OO", "MONKEY_BUSINESS", NULL); - return TCL_ERROR; + return TCL_ERROR; } /* @@ -1971,7 +1971,7 @@ TclOODefineMethodObjCmd( Tcl_WrongNumArgs(interp, 1, objv, "name ?option? args body"); return TCL_ERROR; } - + oPtr = (Object *) TclOOGetDefineCmdContext(interp); if (oPtr == NULL) { return TCL_ERROR; diff --git a/generic/tclObj.c b/generic/tclObj.c index e57b86e..6e3db3e 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -1697,15 +1697,15 @@ Tcl_GetStringFromObj( * This function is called in several configurations to provide all * the tools needed to set an object's string representation. The * function is determined by the arguments. - * + * * (objPtr->bytes != NULL && bytes != NULL) || (numBytes == -1) * Invalid call -- panic! - * + * * objPtr->bytes == NULL && bytes == NULL && numBytes >= 0 * Allocation only - allocate space for (numBytes+1) chars. * store in objPtr->bytes and return. Also sets * objPtr->length to 0 and objPtr->bytes[0] to NUL. - * + * * objPtr->bytes == NULL && bytes != NULL && numBytes >= 0 * Allocate and copy. bytes is assumed to point to chars to * copy into the string rep. objPtr->length = numBytes. Allocate diff --git a/generic/tclParse.c b/generic/tclParse.c index 7b5de0f..e0b46e6 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -2505,7 +2505,7 @@ TclObjCommandComplete( Tcl_Obj *objPtr) /* Points to object holding script to * check. */ { - int length; + size_t length; const char *script = TclGetStringFromObj(objPtr, &length); return CommandComplete(script, length); diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c index 09e54a1..2cd41a9 100644 --- a/generic/tclRegexp.c +++ b/generic/tclRegexp.c @@ -593,7 +593,7 @@ Tcl_GetRegExpFromObj( * expression. */ int flags) /* Regular expression compilation flags. */ { - int length; + size_t length; TclRegexp *regexpPtr; const char *pattern; diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 4ca7b62..715dbc1 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2078,7 +2078,7 @@ Tcl_AppendFormatToObj( switch (ch) { case 'd': { - int length; + size_t length; Tcl_Obj *pure; const char *bytes; @@ -2113,10 +2113,10 @@ Tcl_AppendFormatToObj( */ if (gotPrecision) { - if (length < precision) { + if (length < (size_t)precision) { segmentLimit -= precision - length; } - while (length < precision) { + while (length < (size_t)precision) { Tcl_AppendToObj(segment, "0", 1); length++; } @@ -2124,10 +2124,10 @@ Tcl_AppendFormatToObj( } if (gotZero) { length += Tcl_GetCharLength(segment); - if (length < width) { + if (length < (size_t)width) { segmentLimit -= width - length; } - while (length < width) { + while (length < (size_t)width) { Tcl_AppendToObj(segment, "0", 1); length++; } @@ -2150,7 +2150,8 @@ Tcl_AppendFormatToObj( case 'b': { Tcl_WideUInt bits = 0; Tcl_WideInt numDigits = 0; - int length, numBits = 4, base = 16, index = 0, shift = 0; + int numBits = 4, base = 16, index = 0, shift = 0; + size_t length; Tcl_Obj *pure; char *bytes; @@ -2244,10 +2245,10 @@ Tcl_AppendFormatToObj( mp_clear(&big); } if (gotPrecision) { - if (length < precision) { + if (length < (size_t)precision) { segmentLimit -= precision - length; } - while (length < precision) { + while (length < (size_t)precision) { Tcl_AppendToObj(segment, "0", 1); length++; } @@ -2255,10 +2256,10 @@ Tcl_AppendFormatToObj( } if (gotZero) { length += Tcl_GetCharLength(segment); - if (length < width) { + if (length < (size_t)width) { segmentLimit -= width - length; } - while (length < width) { + while (length < (size_t)width) { Tcl_AppendToObj(segment, "0", 1); length++; } diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index 018d057..0a7e8b1 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -1348,7 +1348,7 @@ TeststringobjCmd( if (objc != 3) { goto wrongNumArgs; } - Tcl_GetUnicodeFromObj(varPtr[varIndex], NULL); + Tcl_GetUnicode(varPtr[varIndex]); break; case 11: /* appendself */ if (objc != 4) { diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 74ab749..24f5206 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3429,7 +3429,7 @@ GetWideForIndex( * NULL, then no error message is left after * errors. */ Tcl_Obj *objPtr, /* Points to the value to be parsed */ - Tcl_WideInt endValue, /* The value to be stored at *widePtr if + Tcl_WideInt endValue, /* The value to be stored at *widePtr if * objPtr holds "end". * NOTE: this value may be negative. */ Tcl_WideInt *widePtr) /* Location filled in with a wide integer @@ -3632,7 +3632,7 @@ TclGetIntForIndex( * errors. */ Tcl_Obj *objPtr, /* Points to an object containing either "end" * or an integer. */ - int endValue, /* The value to be stored at "indexPtr" if + size_t endValue, /* The value to be stored at "indexPtr" if * "objPtr" holds "end". */ int *indexPtr) /* Location filled in with an integer * representing an index. */ @@ -3671,7 +3671,7 @@ TclGetIntForIndex( static int GetEndOffsetFromObj( Tcl_Obj *objPtr, /* Pointer to the object to parse */ - Tcl_WideInt endValue, /* The value to be stored at "indexPtr" if + Tcl_WideInt endValue, /* The value to be stored at "indexPtr" if * "objPtr" holds "end". */ Tcl_WideInt *widePtr) /* Location filled in with an integer * representing an index. */ @@ -3681,7 +3681,7 @@ GetEndOffsetFromObj( while ((irPtr = Tcl_FetchIntRep(objPtr, &endOffsetType)) == NULL) { Tcl_ObjIntRep ir; - int length; + size_t length; const char *bytes = TclGetStringFromObj(objPtr, &length); if ((length < 3) || (length == 4)) { @@ -3819,8 +3819,8 @@ int TclIndexEncode( Tcl_Interp *interp, /* For error reporting, may be NULL */ Tcl_Obj *objPtr, /* Index value to parse */ - int before, /* Value to return for index before beginning */ - int after, /* Value to return for index after end */ + size_t before, /* Value to return for index before beginning */ + size_t after, /* Value to return for index after end */ int *indexPtr) /* Where to write the encoded answer, not NULL */ { ClientData cd; @@ -3848,7 +3848,7 @@ TclIndexEncode( */ if (wide > 0) { /* - * All end+postive or end-negative expressions + * All end+positive or end-negative expressions * always indicate "after the end". */ idx = after; @@ -3894,7 +3894,7 @@ TclIndexEncode( int TclIndexDecode( int encoded, /* Value to decode */ - int endValue) /* Meaning of "end" to use, > TCL_INDEX_END */ + size_t endValue) /* Meaning of "end" to use, > TCL_INDEX_END */ { if (encoded <= TCL_INDEX_END) { return (encoded - TCL_INDEX_END) + endValue; @@ -4298,7 +4298,7 @@ int TclReToGlob( Tcl_Interp *interp, const char *reStr, - int reStrLen, + size_t reStrLen, Tcl_DString *dsPtr, int *exactPtr, int *quantifiersFoundPtr) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 97bb229..4a4faa7 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -1902,7 +1902,7 @@ ZipFSMountBufferObjCmd( { const char *mountPoint; /* Mount point path. */ unsigned char *data; - int length; + size_t length; if (objc > 4) { Tcl_WrongNumArgs(interp, 1, objv, "?mountpoint? ?data?"); @@ -1925,7 +1925,7 @@ ZipFSMountBufferObjCmd( return TCL_OK; } - data = Tcl_GetByteArrayFromObj(objv[2], &length); + data = TclGetByteArrayFromObj(objv[2], &length); return TclZipfs_MountBuffer(interp, mountPoint, data, length, 1); } diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index a17e598..3da84e0 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -41,7 +41,7 @@ TclpFindExecutable( { Tcl_Encoding encoding; #ifdef __CYGWIN__ - int length; + size_t length; char buf[PATH_MAX * 2]; char name[PATH_MAX * TCL_UTF_MAX + 1]; GetModuleFileNameW(NULL, buf, PATH_MAX); diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c index 47af1e1..e448493 100644 --- a/win/tclWinPipe.c +++ b/win/tclWinPipe.c @@ -3108,7 +3108,8 @@ TclpOpenTemporaryFile( char *namePtr; HANDLE handle; DWORD flags = FILE_ATTRIBUTE_TEMPORARY; - int length, counter, counter2; + size_t length; + int counter, counter2; Tcl_DString buf; if (!resultingNameObj) { @@ -3130,7 +3131,7 @@ TclpOpenTemporaryFile( Tcl_DStringFree(&buf); } else { const TCHAR *baseStr = TEXT("TCL"); - int length = 3 * sizeof(TCHAR); + length = 3 * sizeof(TCHAR); memcpy(namePtr, baseStr, length); namePtr += length; diff --git a/win/tclWinTest.c b/win/tclWinTest.c index 55d192b..0fef801 100644 --- a/win/tclWinTest.c +++ b/win/tclWinTest.c @@ -572,7 +572,7 @@ TestplatformChmod( */ if (set_readOnly == acl_readOnly_found || SetNamedSecurityInfoA( - (LPSTR) nativePath, SE_FILE_OBJECT, + (LPSTR) nativePath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION /*| PROTECTED_DACL_SECURITY_INFORMATION*/, NULL, NULL, newAcl, NULL) == ERROR_SUCCESS) { res = 0; -- cgit v0.12