From 7d7b549619c459b43235329d1eafcff775e2828e Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 10 Aug 2018 06:39:54 +0000 Subject: Eliminate type-casts, by using size_t type internally in more situations. No functional changes --- generic/tkConfig.c | 7 ++----- generic/tkMenu.c | 4 ++-- generic/tkObj.c | 6 +++--- generic/tkOldTest.c | 4 ++-- generic/tkPanedWindow.c | 9 +++------ generic/tkText.c | 47 ++++++++++++++++++++++++----------------------- generic/tkTextIndex.c | 2 +- generic/tkUtil.c | 2 +- generic/ttk/ttkState.c | 7 ++++--- win/tkWinDialog.c | 4 ++-- 10 files changed, 44 insertions(+), 48 deletions(-) diff --git a/generic/tkConfig.c b/generic/tkConfig.c index 9c159e6..53a9612 100644 --- a/generic/tkConfig.c +++ b/generic/tkConfig.c @@ -937,16 +937,13 @@ static int ObjectIsEmpty( Tcl_Obj *objPtr) /* Object to test. May be NULL. */ { - int length; - if (objPtr == NULL) { return 1; } if (objPtr->bytes != NULL) { - return (objPtr->length == 0); + Tcl_GetString(objPtr); } - (void)Tcl_GetStringFromObj(objPtr, &length); - return (length == 0); + return (objPtr->length == 0); } /* diff --git a/generic/tkMenu.c b/generic/tkMenu.c index 5859ac0..26ffc88 100644 --- a/generic/tkMenu.c +++ b/generic/tkMenu.c @@ -1700,12 +1700,12 @@ PostProcessEntry( if (mePtr->labelPtr == NULL) { mePtr->labelLength = 0; } else { - (void)Tcl_GetStringFromObj(mePtr->labelPtr, &mePtr->labelLength); + Tcl_GetStringFromObj(mePtr->labelPtr, &mePtr->labelLength); } if (mePtr->accelPtr == NULL) { mePtr->accelLength = 0; } else { - (void)Tcl_GetStringFromObj(mePtr->accelPtr, &mePtr->accelLength); + Tcl_GetStringFromObj(mePtr->accelPtr, &mePtr->accelLength); } /* diff --git a/generic/tkObj.c b/generic/tkObj.c index e6952ff..46f2da5 100644 --- a/generic/tkObj.c +++ b/generic/tkObj.c @@ -668,7 +668,7 @@ UpdateStringOfMM( { MMRep *mmPtr; char buffer[TCL_DOUBLE_SPACE]; - register int len; + size_t len; mmPtr = objPtr->internalRep.twoPtrValue.ptr1; /* assert( mmPtr->units == -1 && objPtr->bytes == NULL ); */ @@ -677,7 +677,7 @@ UpdateStringOfMM( } Tcl_PrintDouble(NULL, mmPtr->value, buffer); - len = (int)strlen(buffer); + len = strlen(buffer); objPtr->bytes = ckalloc(len + 1); strcpy(objPtr->bytes, buffer); @@ -892,7 +892,7 @@ SetWindowFromAny( * Free the old internalRep before setting the new one. */ - (void)Tcl_GetString(objPtr); + Tcl_GetString(objPtr); typePtr = objPtr->typePtr; if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) { typePtr->freeIntRepProc(objPtr); diff --git a/generic/tkOldTest.c b/generic/tkOldTest.c index df1bb6c..f78ebba 100644 --- a/generic/tkOldTest.c +++ b/generic/tkOldTest.c @@ -172,9 +172,9 @@ ImageCreate( timPtr->interp = interp; timPtr->width = 30; timPtr->height = 15; - timPtr->imageName = ckalloc((unsigned) (strlen(name) + 1)); + timPtr->imageName = ckalloc(strlen(name) + 1); strcpy(timPtr->imageName, name); - timPtr->varName = ckalloc((unsigned) (strlen(varName) + 1)); + timPtr->varName = ckalloc(strlen(varName) + 1); strcpy(timPtr->varName, varName); Tcl_CreateObjCommand(interp, name, ImageObjCmd, timPtr, NULL); *clientDataPtr = timPtr; diff --git a/generic/tkPanedWindow.c b/generic/tkPanedWindow.c index 17e2b4a..45d784a 100644 --- a/generic/tkPanedWindow.c +++ b/generic/tkPanedWindow.c @@ -2992,16 +2992,13 @@ static int ObjectIsEmpty( Tcl_Obj *objPtr) /* Object to test. May be NULL. */ { - int length; - if (objPtr == NULL) { return 1; } - if (objPtr->bytes != NULL) { - return (objPtr->length == 0); + if (objPtr->bytes == NULL) { + Tcl_GetString(objPtr); } - (void)Tcl_GetStringFromObj(objPtr, &length); - return (length == 0); + return (objPtr->length == 0); } /* diff --git a/generic/tkText.c b/generic/tkText.c index 78260e0..d43bef6 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -864,7 +864,8 @@ TextWidgetObjCmd( } for (i = 2; i < objc-2; i++) { - int value, length; + int value; + size_t length; const char *option = Tcl_GetString(objv[i]); char c; @@ -873,19 +874,19 @@ TextWidgetObjCmd( goto badOption; } c = option[1]; - if (c == 'c' && !strncmp("-chars", option, (unsigned) length)) { + if (c == 'c' && !strncmp("-chars", option, length)) { value = CountIndices(textPtr, indexFromPtr, indexToPtr, COUNT_CHARS); } else if (c == 'd' && (length > 8) - && !strncmp("-displaychars", option, (unsigned) length)) { + && !strncmp("-displaychars", option, length)) { value = CountIndices(textPtr, indexFromPtr, indexToPtr, COUNT_DISPLAY_CHARS); } else if (c == 'd' && (length > 8) - && !strncmp("-displayindices", option,(unsigned)length)) { + && !strncmp("-displayindices", option,length)) { value = CountIndices(textPtr, indexFromPtr, indexToPtr, COUNT_DISPLAY_INDICES); } else if (c == 'd' && (length > 8) - && !strncmp("-displaylines", option, (unsigned) length)) { + && !strncmp("-displaylines", option, length)) { TkTextLine *fromPtr, *lastPtr; TkTextIndex index, index2; @@ -983,19 +984,19 @@ TextWidgetObjCmd( value = -value; } } else if (c == 'i' - && !strncmp("-indices", option, (unsigned) length)) { + && !strncmp("-indices", option, length)) { value = CountIndices(textPtr, indexFromPtr, indexToPtr, COUNT_INDICES); } else if (c == 'l' - && !strncmp("-lines", option, (unsigned) length)) { + && !strncmp("-lines", option, length)) { value = TkBTreeLinesTo(textPtr, indexToPtr->linePtr) - TkBTreeLinesTo(textPtr, indexFromPtr->linePtr); } else if (c == 'u' - && !strncmp("-update", option, (unsigned) length)) { + && !strncmp("-update", option, length)) { update = 1; continue; } else if (c == 'x' - && !strncmp("-xpixels", option, (unsigned) length)) { + && !strncmp("-xpixels", option, length)) { int x1, x2; TkTextIndex index; @@ -1005,7 +1006,7 @@ TextWidgetObjCmd( TkTextFindDisplayLineEnd(textPtr, &index, 0, &x2); value = x2 - x1; } else if (c == 'y' - && !strncmp("-ypixels", option, (unsigned) length)) { + && !strncmp("-ypixels", option, length)) { if (update) { TkTextUpdateLineMetrics(textPtr, TkBTreeLinesTo(textPtr, indexFromPtr->linePtr), @@ -1155,14 +1156,14 @@ TextWidgetObjCmd( objc++; } useIdx = ckalloc(objc); - memset(useIdx, 0, (unsigned) objc); + memset(useIdx, 0, (size_t) objc); /* * Do a decreasing order sort so that we delete the end ranges * first to maintain index consistency. */ - qsort(indices, (unsigned) objc / 2, + qsort(indices, (size_t) objc / 2, 2 * sizeof(TkTextIndex), TextIndexSortProc); lastStart = NULL; @@ -1260,7 +1261,7 @@ TextWidgetObjCmd( Tcl_Obj *objPtr = NULL; int i, found = 0, visible = 0; const char *name; - int length; + size_t length; if (objc < 3) { Tcl_WrongNumArgs(interp, 2, objv, @@ -1279,7 +1280,7 @@ TextWidgetObjCmd( name = Tcl_GetString(objv[i]); length = objv[i]->length; if (length > 1 && name[0] == '-') { - if (strncmp("-displaychars", name, (unsigned) length) == 0) { + if (strncmp("-displaychars", name, length) == 0) { i++; visible = 1; name = Tcl_GetString(objv[i]); @@ -2633,7 +2634,8 @@ InsertChars( * information to add to text. */ int viewUpdate) /* Update the view if set. */ { - int lineIndex, length; + int lineIndex; + size_t length; TkText *tPtr; int *lineAndByteIndex; int resetViewCount; @@ -4182,7 +4184,7 @@ TextSearchAddNextLine( if (lenPtr != NULL) { if (searchSpecPtr->exact) { - (void)Tcl_GetString(theLine); + Tcl_GetString(theLine); *lenPtr = theLine->length; } else { *lenPtr = Tcl_GetCharLength(theLine); @@ -4707,7 +4709,7 @@ TextDumpCmd( if (objc == arg) { TkTextIndexForwChars(NULL, &index1, 1, &index2, COUNT_INDICES); } else { - int length; + size_t length; const char *str; if (TkTextGetObjIndex(interp, textPtr, objv[arg], &index2) != TCL_OK) { @@ -4715,7 +4717,7 @@ TextDumpCmd( } str = Tcl_GetString(objv[arg]); length = objv[arg]->length; - if (strncmp(str, "end", (unsigned) length) == 0) { + if (strncmp(str, "end", length) == 0) { atEnd = 1; } } @@ -5920,7 +5922,7 @@ SearchCore( } while (p >= startOfLine + firstOffset) { if (p[0] == c && !strncmp(p, pattern, - (unsigned) matchLength)) { + (size_t) matchLength)) { goto backwardsMatch; } p--; @@ -6015,7 +6017,7 @@ SearchCore( * result. */ - if (strncmp(p,pattern,(unsigned)matchLength)) { + if (strncmp(p,pattern,(size_t)matchLength)) { p = NULL; } break; @@ -6822,10 +6824,9 @@ ObjectIsEmpty( if (objPtr == NULL) { return 1; } - if (objPtr->bytes != NULL) { - return (objPtr->length == 0); + if (objPtr->bytes == NULL) { + Tcl_GetString(objPtr); } - (void)Tcl_GetString(objPtr); return (objPtr->length == 0); } diff --git a/generic/tkTextIndex.c b/generic/tkTextIndex.c index 2b5b569..582e1a8 100644 --- a/generic/tkTextIndex.c +++ b/generic/tkTextIndex.c @@ -134,7 +134,7 @@ UpdateStringOfTextIndex( Tcl_Obj *objPtr) { char buffer[TK_POS_CHARS]; - register int len; + size_t len; const TkTextIndex *indexPtr = GET_TEXTINDEX(objPtr); len = TkTextPrintIndex(indexPtr->textPtr, indexPtr, buffer); diff --git a/generic/tkUtil.c b/generic/tkUtil.c index ff5bd98..1942975 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -733,7 +733,7 @@ Tk_GetScrollInfoObj( size_t length = objv[2]->length; #define ArgPfxEq(str) \ - ((arg[0] == str[0]) && !strncmp(arg, str, (unsigned)length)) + ((arg[0] == str[0]) && !strncmp(arg, str, length)) if (ArgPfxEq("moveto")) { if (objc != 4) { diff --git a/generic/ttk/ttkState.c b/generic/ttk/ttkState.c index c34b900..2941ca8 100644 --- a/generic/ttk/ttkState.c +++ b/generic/ttk/ttkState.c @@ -130,7 +130,8 @@ static void StateSpecUpdateString(Tcl_Obj *objPtr) unsigned int offbits = objPtr->internalRep.longValue & 0x0000FFFF; unsigned int mask = onbits | offbits; Tcl_DString result; - int i, len; + int i; + size_t len; Tcl_DStringInit(&result); @@ -146,9 +147,9 @@ static void StateSpecUpdateString(Tcl_Obj *objPtr) len = Tcl_DStringLength(&result); if (len) { /* 'len' includes extra trailing ' ' */ - objPtr->bytes = Tcl_Alloc((unsigned)len); + objPtr->bytes = Tcl_Alloc(len); objPtr->length = len-1; - strncpy(objPtr->bytes, Tcl_DStringValue(&result), (size_t)len-1); + strncpy(objPtr->bytes, Tcl_DStringValue(&result), len-1); objPtr->bytes[len-1] = '\0'; } else { /* empty string */ diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c index f97d813..d6d2c7d 100644 --- a/win/tkWinDialog.c +++ b/win/tkWinDialog.c @@ -3378,7 +3378,7 @@ FontchooserConfigureCmd( if (hdPtr->fontObj) { Tcl_DecrRefCount(hdPtr->fontObj); } - (void)Tcl_GetString(objv[i+1]); + Tcl_GetString(objv[i+1]); if (objv[i+1]->length) { hdPtr->fontObj = objv[i+1]; if (Tcl_IsShared(hdPtr->fontObj)) { @@ -3393,7 +3393,7 @@ FontchooserConfigureCmd( if (hdPtr->cmdObj) { Tcl_DecrRefCount(hdPtr->cmdObj); } - (void)Tcl_GetString(objv[i+1]); + Tcl_GetString(objv[i+1]); if (objv[i+1]->length) { hdPtr->cmdObj = objv[i+1]; if (Tcl_IsShared(hdPtr->cmdObj)) { -- cgit v0.12