From a8fc23ad3082f9c2b2729c15b0e21056be501432 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 15 Apr 2025 07:11:51 +0000 Subject: Fix more -Wconversion warnings --- generic/tclBasic.c | 6 +++--- generic/tclDictObj.c | 15 +++++++++------ generic/tclInt.h | 28 ++++++++++++++-------------- generic/tclParse.c | 10 +++++----- generic/tclResult.c | 2 +- generic/tclTrace.c | 14 +++++++------- generic/tclVar.c | 36 ++++++++++++++++++++---------------- 7 files changed, 59 insertions(+), 52 deletions(-) diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 3cbf091..317f6de 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -2734,7 +2734,7 @@ cmdWrapperProc( if (objc < 0) { objc = -1; } - return info->proc(info->clientData, interp, objc, objv); + return info->proc(info->clientData, interp, (int)objc, objv); } static void @@ -5671,7 +5671,7 @@ void TclAdvanceContinuations( Tcl_Size *line, Tcl_Size **clNextPtrPtr, - int loc) + Tcl_Size loc) { /* * Track the invisible continuation lines embedded in a script, if any. @@ -7715,7 +7715,7 @@ ExprRandFunc( * take into consideration the thread this interp is running in. */ - iPtr->randSeed = TclpGetClicks() + PTR2UINT(Tcl_GetCurrentThread()) * 4093U; + iPtr->randSeed = (long)TclpGetClicks() + (long)PTR2UINT(Tcl_GetCurrentThread()) * 4093U; /* * Make sure 1 <= randSeed <= (2^31) - 2. See below. diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c index 9c1734b..892ba87 100644 --- a/generic/tclDictObj.c +++ b/generic/tclDictObj.c @@ -546,7 +546,9 @@ UpdateStringOfDict( dst = Tcl_InitStringRep(dictPtr, NULL, bytesNeeded - 1); TclOOM(dst, bytesNeeded); for (i=0,cPtr=dict->entryChainHead; inextPtr) { - flagPtr[i] |= ( i ? TCL_DONT_QUOTE_HASH : 0 ); + if (i) { + flagPtr[i] |= TCL_DONT_QUOTE_HASH; + } keyPtr = (Tcl_Obj *)Tcl_GetHashKey(&dict->table, &cPtr->entry); elem = TclGetStringFromObj(keyPtr, &length); dst += TclConvertElement(elem, length, dst, flagPtr[i]); @@ -1967,8 +1969,8 @@ DictMergeCmd( Tcl_Obj *const *objv) { Tcl_Obj *targetObj, *keyObj = NULL, *valueObj = NULL; - int allocatedDict = 0; - int i, done; + int done, allocatedDict = 0; + int i; Tcl_DictSearch search; if (objc == 1) { @@ -2493,7 +2495,8 @@ DictLappendCmd( Tcl_Obj *const *objv) { Tcl_Obj *dictPtr, *valuePtr, *resultPtr; - int i, allocatedDict = 0, allocatedValue = 0; + int allocatedDict = 0, allocatedValue = 0; + int i; if (objc < 3) { Tcl_WrongNumArgs(interp, 1, objv, "dictVarName key ?value ...?"); @@ -3855,10 +3858,10 @@ TclDictWithFinish( * parameter is >= 0 */ Tcl_Obj *part2Ptr, /* If non-NULL, gives the name of an element * in the array part1. */ - int index, /* Index into the local variable table of the + Tcl_Size index, /* Index into the local variable table of the * variable, or -1. Only used when part1Ptr is * NULL. */ - int pathc, /* The number of elements in the path into the + Tcl_Size pathc, /* The number of elements in the path into the * dictionary. */ Tcl_Obj *const pathv[], /* The elements of the path to the subdict. */ Tcl_Obj *keysPtr) /* List of keys to be synchronized. This is diff --git a/generic/tclInt.h b/generic/tclInt.h index e266f62..16dcac9 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -2168,7 +2168,7 @@ typedef struct Interp { * invoking context of the bytecode compiler. * NULL when the byte code compiler is not * active. */ - int invokeWord; /* Index of the word in the command which + Tcl_Size invokeWord; /* Index of the word in the command which * is getting compiled. */ Tcl_HashTable *linePBodyPtr;/* This table remembers for each statically * defined procedure the location information @@ -3229,7 +3229,7 @@ struct Tcl_LoadHandle_ { */ MODULE_SCOPE void TclAdvanceContinuations(Tcl_Size *line, Tcl_Size **next, - int loc); + Tcl_Size loc); MODULE_SCOPE void TclAdvanceLines(Tcl_Size *line, const char *start, const char *end); MODULE_SCOPE void TclAppendBytesToByteArray(Tcl_Obj *objPtr, @@ -3260,7 +3260,7 @@ MODULE_SCOPE void TclChannelPreserve(Tcl_Channel chan); MODULE_SCOPE void TclChannelRelease(Tcl_Channel chan); MODULE_SCOPE int TclChannelGetBlockingMode(Tcl_Channel chan); MODULE_SCOPE int TclCheckArrayTraces(Tcl_Interp *interp, Var *varPtr, - Var *arrayPtr, Tcl_Obj *name, int index); + Var *arrayPtr, Tcl_Obj *name, Tcl_Size index); MODULE_SCOPE int TclCheckEmptyString(Tcl_Obj *objPtr); MODULE_SCOPE int TclChanCaughtErrorBypass(Tcl_Interp *interp, Tcl_Channel chan); @@ -3440,7 +3440,7 @@ MODULE_SCOPE Tcl_Command TclMakeEnsemble(Tcl_Interp *interp, const char *name, const EnsembleImplMap map[]); MODULE_SCOPE Tcl_Size TclMaxListLength(const char *bytes, Tcl_Size numBytes, const char **endPtr); -MODULE_SCOPE int TclMergeReturnOptions(Tcl_Interp *interp, int objc, +MODULE_SCOPE int TclMergeReturnOptions(Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[], Tcl_Obj **optionsPtrPtr, int *codePtr, int *levelPtr); MODULE_SCOPE Tcl_Obj * TclNoErrorStack(Tcl_Interp *interp, Tcl_Obj *options); @@ -3449,13 +3449,13 @@ MODULE_SCOPE void TclNsDecrRefCount(Namespace *nsPtr); MODULE_SCOPE int TclNamespaceDeleted(Namespace *nsPtr); MODULE_SCOPE void TclObjVarErrMsg(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, const char *operation, - const char *reason, int index); + const char *reason, Tcl_Size index); MODULE_SCOPE int TclObjInvokeNamespace(Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[], Tcl_Namespace *nsPtr, int flags); MODULE_SCOPE int TclObjUnsetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags); -MODULE_SCOPE int TclParseBackslash(const char *src, +MODULE_SCOPE Tcl_Size TclParseBackslash(const char *src, Tcl_Size numBytes, Tcl_Size *readPtr, char *dst); MODULE_SCOPE int TclParseNumber(Tcl_Interp *interp, Tcl_Obj *objPtr, const char *expected, const char *bytes, @@ -3690,7 +3690,7 @@ MODULE_SCOPE Tcl_ObjCmdProc TclDefaultBgErrorHandlerObjCmd; MODULE_SCOPE Tcl_Command TclInitDictCmd(Tcl_Interp *interp); MODULE_SCOPE int TclDictWithFinish(Tcl_Interp *interp, Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr, - Tcl_Obj *part2Ptr, int index, int pathc, + Tcl_Obj *part2Ptr, Tcl_Size index, Tcl_Size pathc, Tcl_Obj *const pathv[], Tcl_Obj *keysPtr); MODULE_SCOPE Tcl_Obj * TclDictWithInit(Tcl_Interp *interp, Tcl_Obj *dictPtr, Tcl_Size pathc, Tcl_Obj *const pathv[]); @@ -3981,25 +3981,25 @@ MODULE_SCOPE Var * TclLookupArrayElement(Tcl_Interp *interp, Tcl_Obj *arrayNamePtr, Tcl_Obj *elNamePtr, int flags, const char *msg, int createPart1, int createPart2, - Var *arrayPtr, int index); + Var *arrayPtr, Tcl_Size index); MODULE_SCOPE Tcl_Obj * TclPtrGetVarIdx(Tcl_Interp *interp, Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr, - Tcl_Obj *part2Ptr, int flags, int index); + Tcl_Obj *part2Ptr, int flags, Tcl_Size index); MODULE_SCOPE Tcl_Obj * TclPtrSetVarIdx(Tcl_Interp *interp, Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, Tcl_Obj *newValuePtr, - int flags, int index); + int flags, Tcl_Size index); MODULE_SCOPE Tcl_Obj * TclPtrIncrObjVarIdx(Tcl_Interp *interp, Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, Tcl_Obj *incrPtr, - int flags, int index); + int flags, Tcl_Size index); MODULE_SCOPE int TclPtrObjMakeUpvarIdx(Tcl_Interp *interp, Var *otherPtr, Tcl_Obj *myNamePtr, int myFlags, int index); MODULE_SCOPE int TclPtrUnsetVarIdx(Tcl_Interp *interp, Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags, - int index); + Tcl_Size index); MODULE_SCOPE void TclInvalidateNsPath(Namespace *nsPtr); MODULE_SCOPE void TclFindArrayPtrElements(Var *arrayPtr, Tcl_HashTable *tablePtr); @@ -4010,7 +4010,7 @@ MODULE_SCOPE void TclFindArrayPtrElements(Var *arrayPtr, MODULE_SCOPE int TclObjCallVarTraces(Interp *iPtr, Var *arrayPtr, Var *varPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, - int flags, int leaveErrMsg, int index); + int flags, int leaveErrMsg, Tcl_Size index); /* * So tclObj.c and tclDictObj.c can share these implementations. @@ -4496,7 +4496,7 @@ MODULE_SCOPE const TclFileAttrProcs tclpFileAttrProcs[]; do { \ Tcl_Obj *bignumObj = (objPtr); \ int bignumPayload = \ - PTR2INT(bignumObj->internalRep.twoPtrValue.ptr2); \ + (int)PTR2INT(bignumObj->internalRep.twoPtrValue.ptr2); \ if (bignumPayload == -1) { \ (bignum) = *((mp_int *) bignumObj->internalRep.twoPtrValue.ptr1); \ } else { \ diff --git a/generic/tclParse.c b/generic/tclParse.c index 3879733..872ccb5 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -129,7 +129,7 @@ static Tcl_Size ParseWhiteSpace(const char *src, Tcl_Size numBytes, int *incompletePtr, char *typePtr); static Tcl_Size ParseAllWhiteSpace(const char *src, Tcl_Size numBytes, int *incompletePtr); -static int ParseHex(const char *src, Tcl_Size numBytes, +static Tcl_Size ParseHex(const char *src, Tcl_Size numBytes, int *resultPtr); /* @@ -724,7 +724,7 @@ TclParseAllWhiteSpace( *---------------------------------------------------------------------- */ -int +Tcl_Size ParseHex( const char *src, /* First character to parse. */ Tcl_Size numBytes, /* Max number of byes to scan */ @@ -779,7 +779,7 @@ ParseHex( *---------------------------------------------------------------------- */ -int +Tcl_Size TclParseBackslash( const char *src, /* Points to the backslash character of a * backslash sequence. */ @@ -1329,7 +1329,7 @@ Tcl_ParseVarName( { Tcl_Token *tokenPtr; const char *src; - int varIndex; + Tcl_Size varIndex; unsigned array; if (numBytes < 0 && start) { @@ -2166,7 +2166,7 @@ TclSubstTokens( for (; count>0 && code==TCL_OK ; count--, tokenPtr++) { Tcl_Obj *appendObj = NULL; const char *append = NULL; - int appendByteLength = 0; + Tcl_Size appendByteLength = 0; char utfCharBytes[4] = ""; switch (tokenPtr->type) { diff --git a/generic/tclResult.c b/generic/tclResult.c index 2e7d378..8890079 100644 --- a/generic/tclResult.c +++ b/generic/tclResult.c @@ -807,7 +807,7 @@ TclProcessReturn( int TclMergeReturnOptions( Tcl_Interp *interp, /* Current interpreter. */ - int objc, /* Number of arguments. */ + Tcl_Size objc, /* Number of arguments. */ Tcl_Obj *const objv[], /* Argument objects. */ Tcl_Obj **optionsPtrPtr, /* If not NULL, points to space for a (Tcl_Obj * *) where the pointer to the merged return diff --git a/generic/tclTrace.c b/generic/tclTrace.c index f1d83e7..71572e0 100644 --- a/generic/tclTrace.c +++ b/generic/tclTrace.c @@ -1995,10 +1995,10 @@ traceWrapperProc( Tcl_Obj *const objv[]) { TraceWrapperInfo *info = (TraceWrapperInfo *)clientData; - if (objc > INT_MAX) { + if (objc > INT_MAX || objc < 0) { objc = -1; /* Signal Tcl_CmdObjTraceProc that objc is out of range */ } - return info->proc(info->clientData, interp, (int)level, command, commandInfo, objc, objv); + return info->proc(info->clientData, interp, (int)level, command, commandInfo, (int)objc, objv); } static void @@ -2187,8 +2187,8 @@ StringTraceProc( * either command or argv. */ - data->proc(data->clientData, interp, level, (char *) command, - cmdPtr->proc, cmdPtr->clientData, objc, argv); + data->proc(data->clientData, interp, (int)level, (char *) command, + cmdPtr->proc, cmdPtr->clientData, (int)objc, argv); TclStackFree(interp, (void *) argv); return TCL_OK; @@ -2393,7 +2393,7 @@ TclCheckArrayTraces( Var *varPtr, Var *arrayPtr, Tcl_Obj *name, - int index) + Tcl_Size index) { int code = TCL_OK; @@ -2446,7 +2446,7 @@ TclObjCallVarTraces( int leaveErrMsg, /* If true, and one of the traces indicates an * error, then leave an error message and * stack trace information in *iPTr. */ - int index) /* Index into the local variable table of the + Tcl_Size index) /* Index into the local variable table of the * variable, or -1. Only used when part1Ptr is * NULL. */ { @@ -2528,7 +2528,7 @@ TclCallVarTraces( } while (*p != '\0'); p--; if (*p == ')') { - int offset = (openParen - part1); + Tcl_Size offset = (openParen - part1); char *newPart1; Tcl_DStringInit(&nameCopy); diff --git a/generic/tclVar.c b/generic/tclVar.c index a94744f..dec319e 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -191,7 +191,7 @@ static Tcl_NRPostProc ArrayForLoopCallback; static Tcl_ObjCmdProc ArrayForNRCmd; static void DeleteSearches(Interp *iPtr, Var *arrayVarPtr); static void DeleteArray(Interp *iPtr, Tcl_Obj *arrayNamePtr, - Var *varPtr, int flags, int index); + Var *varPtr, int flags, Tcl_Size index); static int LocateArray(Tcl_Interp *interp, Tcl_Obj *name, Var **varPtrPtr, int *isArrayPtr); static int NotArrayError(Tcl_Interp *interp, Tcl_Obj *name); @@ -201,12 +201,12 @@ static Tcl_Var ObjFindNamespaceVar(Tcl_Interp *interp, static int ObjMakeUpvar(Tcl_Interp *interp, CallFrame *framePtr, Tcl_Obj *otherP1Ptr, const char *otherP2, int otherFlags, - Tcl_Obj *myNamePtr, int myFlags, int index); + Tcl_Obj *myNamePtr, int myFlags, Tcl_Size index); static ArraySearch * ParseSearchId(Tcl_Interp *interp, const Var *varPtr, Tcl_Obj *varNamePtr, Tcl_Obj *handleObj); static void UnsetVarStruct(Var *varPtr, Var *arrayPtr, Interp *iPtr, Tcl_Obj *part1Ptr, - Tcl_Obj *part2Ptr, int flags, int index); + Tcl_Obj *part2Ptr, int flags, Tcl_Size index); /* * TIP #508: [array default] @@ -607,7 +607,8 @@ TclObjLookupVarEx( Var *varPtr; /* Points to the variable's in-frame Var * structure. */ const char *errMsg = NULL; - int index, parsed = 0; + int index; + int parsed = 0; Tcl_Size localIndex; Tcl_Obj *namePtr, *arrayPtr, *elem; @@ -1072,7 +1073,7 @@ TclLookupArrayElement( * element, if it doesn't already exist. If 0, * return error if it doesn't exist. */ Var *arrayPtr, /* Pointer to the array's Var structure. */ - int index) /* If >=0, the index of the local array. */ + Tcl_Size index) /* If >=0, the index of the local array. */ { int isNew; Var *varPtr; @@ -1384,7 +1385,7 @@ TclPtrGetVarIdx( * in the array part1. */ int flags, /* OR-ed combination of TCL_GLOBAL_ONLY, and * TCL_LEAVE_ERR_MSG bits. */ - int index) /* Index into the local variable table of the + Tcl_Size index) /* Index into the local variable table of the * variable, or -1. Only used when part1Ptr is * NULL. */ { @@ -1912,7 +1913,7 @@ TclPtrSetVarIdx( Tcl_Obj *newValuePtr, /* New value for variable. */ int flags, /* OR-ed combination of TCL_GLOBAL_ONLY, and * TCL_LEAVE_ERR_MSG bits. */ - int index) /* Index of local var where part1 is to be + Tcl_Size index) /* Index of local var where part1 is to be * found. */ { Interp *iPtr = (Interp *) interp; @@ -2229,7 +2230,7 @@ TclPtrIncrObjVarIdx( * any of TCL_GLOBAL_ONLY, TCL_NAMESPACE_ONLY, * TCL_APPEND_VALUE, TCL_LIST_ELEMENT, * TCL_LEAVE_ERR_MSG. */ - int index) /* Index into the local variable table of the + Tcl_Size index) /* Index into the local variable table of the * variable, or -1. Only used when part1Ptr is * NULL. */ { @@ -2464,7 +2465,7 @@ TclPtrUnsetVarIdx( int flags, /* OR-ed combination of any of * TCL_GLOBAL_ONLY, TCL_NAMESPACE_ONLY, * TCL_LEAVE_ERR_MSG. */ - int index) /* Index into the local variable table of the + Tcl_Size index) /* Index into the local variable table of the * variable, or -1. Only used when part1Ptr is * NULL. */ { @@ -2550,7 +2551,7 @@ UnsetVarStruct( Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags, - int index) + Tcl_Size index) { Var dummyVar; int traced = TclIsVarTraced(varPtr) @@ -2735,7 +2736,8 @@ Tcl_UnsetObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int i, flags = TCL_LEAVE_ERR_MSG; + int i; + int flags = TCL_LEAVE_ERR_MSG; const char *name; if (objc == 1) { @@ -4486,7 +4488,7 @@ ObjMakeUpvar( * otherP1/otherP2. Must be a scalar. */ int myFlags, /* 0, TCL_GLOBAL_ONLY or TCL_NAMESPACE_ONLY: * indicates scope of myName. */ - int index) /* If the variable to be linked is an indexed + Tcl_Size index) /* If the variable to be linked is an indexed * scalar, this is its index. Otherwise, -1 */ { Interp *iPtr = (Interp *) interp; @@ -4944,7 +4946,8 @@ Tcl_GlobalObjCmd( Tcl_Obj *objPtr, *tailPtr; const char *varName; const char *tail; - int result, i; + int result; + int i; /* * If we are not executing inside a Tcl procedure, just return. @@ -5048,7 +5051,8 @@ Tcl_VariableObjCmd( const char *varName, *tail, *cp; Var *varPtr, *arrayPtr; Tcl_Obj *varValuePtr; - int i, result; + int i; + int result; Tcl_Obj *varNamePtr, *tailPtr; for (i=1 ; i