Description: Patch adds explicit casts to intptr_t or uintptr_t types to prevent casting to/from pointer from/to integers of different size. Author: Sergei Golovan Last-Modified: Wed, 09 Jul 2014 19:20:07 +0400 --- a/generic/bltBgexec.c +++ b/generic/bltBgexec.c @@ -668,7 +668,7 @@ sinkPtr->name = name; sinkPtr->echo = FALSE; sinkPtr->fd = -1; - sinkPtr->file = (Tcl_File)NULL; + sinkPtr->file = (Tcl_File)0; sinkPtr->byteArr = sinkPtr->staticSpace; sinkPtr->size = DEF_BUFFER_SIZE; sinkPtr->encoding = encoding; @@ -726,7 +726,7 @@ Blt_Free(sinkPtr->byteArr); } sinkPtr->fd = -1; - sinkPtr->file = (Tcl_File)NULL; + sinkPtr->file = (Tcl_File)0; #if (TCL_MAJOR_VERSION >= 8) if (sinkPtr->objv != NULL) { register int i; @@ -883,7 +883,7 @@ #else Tcl_DeleteFileHandler(sinkPtr->fd); #endif - sinkPtr->file = (Tcl_File)NULL; + sinkPtr->file = (Tcl_File)0; sinkPtr->fd = -1; #if WINDEBUG --- a/generic/bltTree.c +++ b/generic/bltTree.c @@ -424,7 +424,7 @@ TreeDestroyValues(nodePtr); UnlinkNode(nodePtr); treeObjPtr->nNodes--; - hPtr = Blt_FindHashEntry(&treeObjPtr->nodeTable, (char *)nodePtr->inode); + hPtr = Blt_FindHashEntry(&treeObjPtr->nodeTable, (char *)(intptr_t)nodePtr->inode); assert(hPtr); Blt_DeleteHashEntry(&treeObjPtr->nodeTable, hPtr); nodePtr->inode = -1; @@ -934,7 +934,7 @@ /* Generate an unique serial number for this node. */ do { inode = treeObjPtr->nextInode++; - hPtr = Blt_CreateHashEntry(&treeObjPtr->nodeTable,(char *)inode, + hPtr = Blt_CreateHashEntry(&treeObjPtr->nodeTable,(char *)(intptr_t)inode, &isNew); } while (!isNew); nodePtr = NewNode(treeObjPtr, name, inode); @@ -1030,7 +1030,7 @@ int isNew, result; treeObjPtr = parentPtr->treeObject; - hPtr = Blt_CreateHashEntry(&treeObjPtr->nodeTable,(char *)inode, &isNew); + hPtr = Blt_CreateHashEntry(&treeObjPtr->nodeTable,(char *)(intptr_t)inode, &isNew); if (!isNew) { return NULL; } @@ -1166,7 +1166,7 @@ TreeObject *treeObjPtr = clientPtr->treeObject; Blt_HashEntry *hPtr; - hPtr = Blt_FindHashEntry(&treeObjPtr->nodeTable, (char *)inode); + hPtr = Blt_FindHashEntry(&treeObjPtr->nodeTable, (char *)(intptr_t)inode); if (hPtr != NULL) { return (Blt_TreeNode)Blt_GetHashValue(hPtr); } @@ -1179,7 +1179,7 @@ { Blt_HashEntry *hPtr; - hPtr = Blt_FindHashEntry(&treeObjPtr->nodeTable, (char *)inode); + hPtr = Blt_FindHashEntry(&treeObjPtr->nodeTable, (char *)(intptr_t)inode); if (hPtr != NULL) { return (Node*)Blt_GetHashValue(hPtr); } --- a/generic/bltTreeCmd.c +++ b/generic/bltTreeCmd.c @@ -1641,7 +1641,7 @@ if (parentId == -1) { /* Dump marks root's parent as -1. */ node = dataPtr->root; /* Create a mapping between the old id and the new node */ - hPtr = Blt_CreateHashEntry(&dataPtr->idTable, (char *)nodeId, + hPtr = Blt_CreateHashEntry(&dataPtr->idTable, (char *)(intptr_t)nodeId, &isNew); Blt_SetHashValue(hPtr, node); Blt_TreeRelabelNode(cmdPtr->tree, node, names[0]); @@ -1651,7 +1651,7 @@ * This can happen when there's a id collision with an * existing node. */ - hPtr = Blt_FindHashEntry(&dataPtr->idTable, (char *)parentId); + hPtr = Blt_FindHashEntry(&dataPtr->idTable, (char *)(intptr_t)parentId); if (hPtr != NULL) { parent = Blt_GetHashValue(hPtr); } else { @@ -1688,7 +1688,7 @@ if (dataPtr->flags & RESTORE_OVERWRITE && ((node = Blt_TreeFindChild(parent, names[nNames - 1])))) { /* Create a mapping between the old id and the new node */ - hPtr = Blt_CreateHashEntry(&dataPtr->idTable, (char *)nodeId, + hPtr = Blt_CreateHashEntry(&dataPtr->idTable, (char *)(intptr_t)nodeId, &isNew); Blt_SetHashValue(hPtr, node); } @@ -1698,7 +1698,7 @@ node = Blt_TreeCreateNode(cmdPtr->tree, parent, names[nNames - 1], -1); /* Create a mapping between the old id and the new node */ - hPtr = Blt_CreateHashEntry(&dataPtr->idTable, (char *)nodeId, + hPtr = Blt_CreateHashEntry(&dataPtr->idTable, (char *)(intptr_t)nodeId, &isNew); Blt_SetHashValue(hPtr, node); } else { @@ -2196,7 +2196,7 @@ for (node = Blt_ListFirstNode(patternList); node != NULL; node = Blt_ListNextNode(node)) { - type = (int)Blt_ListGetValue(node); + type = (intptr_t)Blt_ListGetValue(node); pattern = (char *)Blt_ListGetKey(node); switch (type) { case 0: @@ -3654,7 +3654,7 @@ for (hPtr = Blt_FirstHashEntry(tablePtr, &cursor); hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { node = Blt_GetHashValue(hPtr); - Blt_ChainAppend(chainPtr, (ClientData)Blt_TreeNodeId(node)); + Blt_ChainAppend(chainPtr, (ClientData)(intptr_t)Blt_TreeNodeId(node)); } /* * Iterate through this list to delete the nodes. By @@ -3664,7 +3664,7 @@ for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL; linkPtr = nextPtr) { nextPtr = Blt_ChainNextLink(linkPtr); - inode = (int)Blt_ChainGetValue(linkPtr); + inode = (intptr_t)Blt_ChainGetValue(linkPtr); node = Blt_TreeGetNode(cmdPtr->tree, inode); if (node != NULL) { DeleteNode(cmdPtr, node); --- a/generic/bltUnixPipe.c +++ b/generic/bltUnixPipe.c @@ -508,7 +508,7 @@ * Reap the child process now if an error occurred during its * startup. */ - Tcl_WaitPid((Tcl_Pid)pid, &status, WNOHANG); + Tcl_WaitPid((Tcl_Pid)(intptr_t)pid, &status, WNOHANG); } if (errPipeIn >= 0) { CloseFile(errPipeIn); --- a/generic/bltUtil.c +++ b/generic/bltUtil.c @@ -827,10 +827,10 @@ if (isNew) { refCount = 0; } else { - refCount = (int)Blt_GetHashValue(hPtr); + refCount = (intptr_t)Blt_GetHashValue(hPtr); } refCount++; - Blt_SetHashValue(hPtr, (ClientData)refCount); + Blt_SetHashValue(hPtr, (intptr_t)refCount); return (Blt_Uid)Blt_GetHashKey(&uidTable, hPtr); } @@ -864,12 +864,12 @@ if (hPtr) { int refCount; - refCount = (int)Blt_GetHashValue(hPtr); + refCount = (intptr_t)Blt_GetHashValue(hPtr); refCount--; if (refCount == 0) { Blt_DeleteHashEntry(&uidTable, hPtr); } else { - Blt_SetHashValue(hPtr, (ClientData)refCount); + Blt_SetHashValue(hPtr, (intptr_t)refCount); } } else { fprintf(stderr, "tried to release unknown identifier \"%s\"\n", uid); --- a/generic/bltInit.c +++ b/generic/bltInit.c @@ -514,7 +514,7 @@ int dostub = 0; #endif - flags = (int)Tcl_GetAssocData(interp, BLT_THREAD_KEY, NULL); + flags = (intptr_t)Tcl_GetAssocData(interp, BLT_THREAD_KEY, NULL); if ((flags & BLT_TCL_CMDS) == 0) { register Tcl_AppInitProc **p; Tcl_Namespace *nsPtr; @@ -573,7 +573,7 @@ } #endif Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, - (ClientData)(flags | BLT_TCL_CMDS)); + (ClientData)(intptr_t)(flags | BLT_TCL_CMDS)); } #ifndef TCL_ONLY if ((flags & BLT_TK_CMDS) == 0) { @@ -609,7 +609,7 @@ } Blt_InitEpsCanvasItem(interp); Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, - (ClientData)(flags | BLT_TK_CMDS)); + (ClientData)(intptr_t)(flags | BLT_TK_CMDS)); } #endif return TCL_OK; --- a/generic/bltGrAxis.c +++ b/generic/bltGrAxis.c @@ -669,7 +669,7 @@ char *widgRec; /* Pointer to structure record. */ int offset; /* Offset of field in structure. */ { - unsigned int mask = (unsigned int)clientData; + unsigned int mask = (uintptr_t)clientData; Axis *axisPtr = (Axis *)widgRec; Ticks **ticksPtrPtr = (Ticks **) (widgRec + offset); int nTicks; @@ -3687,7 +3687,7 @@ int margin; /* TODO: fix bug where "$g xaxis x2" leaves x unavailable. */ - margin = (int)argv[-1]; + margin = (intptr_t)argv[-1]; chainPtr = graphPtr->margins[margin].axes; if (argc == 0) { for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr!= NULL; @@ -4231,7 +4231,7 @@ return TCL_ERROR; } if (proc == UseOp) { - argv[2] = (char *)margin; /* Hack. Slide a reference to the margin in + argv[2] = (char *)(intptr_t)margin; /* Hack. Slide a reference to the margin in * the argument list. Needed only for UseOp. */ result = (*proc)(graphPtr, NULL, argc - 3, argv +3); --- a/generic/bltGrBar.c +++ b/generic/bltGrBar.c @@ -2197,13 +2197,13 @@ if (isNew) { count = 1; } else { - count = (int)Blt_GetHashValue(hPtr); + count = (intptr_t)Blt_GetHashValue(hPtr); if (count == 1) { nStacks++; } count++; } - Blt_SetHashValue(hPtr, (ClientData)count); + Blt_SetHashValue(hPtr, (ClientData)(intptr_t)count); } } if (nSegs == 0) { @@ -2219,12 +2219,12 @@ infoPtr = graphPtr->freqArr; for (hPtr = Blt_FirstHashEntry(&freqTable, &cursor); hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { - count = (int)Blt_GetHashValue(hPtr); + count = (intptr_t)Blt_GetHashValue(hPtr); keyPtr = (FreqKey *)Blt_GetHashKey(&freqTable, hPtr); if (count > 1) { h2Ptr = Blt_CreateHashEntry(&(graphPtr->freqTable), (char *)keyPtr, &isNew); - count = (int)Blt_GetHashValue(hPtr); + count = (intptr_t)Blt_GetHashValue(hPtr); infoPtr->freq = count; infoPtr->axes = keyPtr->axes; Blt_SetHashValue(h2Ptr, infoPtr); --- a/generic/bltGrMisc.c +++ b/generic/bltGrMisc.c @@ -260,7 +260,7 @@ { ColorPair *pairPtr = (ColorPair *)(widgRec + offset); ColorPair sample; - int allowDefault = (int)clientData; + int allowDefault = (intptr_t)clientData; sample.fgColor = sample.bgColor = NULL; if ((string != NULL) && (*string != '\0')) { --- a/generic/bltConfig.c +++ b/generic/bltConfig.c @@ -442,7 +442,7 @@ char *widgRec; /* Cubicle structure record */ int offset; /* Offset of style in record */ { - unsigned int mask = (unsigned int)clientData; /* Bit to be tested */ + unsigned int mask = (uintptr_t)clientData; /* Bit to be tested */ int *flagPtr = (int *)(widgRec + offset); int bool; @@ -478,7 +478,7 @@ int offset; /* Offset of fill in widget record */ Tcl_FreeProc **freeProcPtr; /* Not Used. */ { - unsigned int mask = (unsigned int)clientData; /* Bit to be tested */ + unsigned int mask = (uintptr_t)clientData; /* Bit to be tested */ unsigned int bool = *(unsigned int *)(widgRec + offset); return (bool & mask) ? "1" : "0"; @@ -559,7 +559,7 @@ int offset; /* Offset of pixel size in record */ { int *valuePtr = (int *)(widgRec + offset); - return Blt_GetPixels(interp, tkwin, string, (int)clientData, valuePtr); + return Blt_GetPixels(interp, tkwin, string, (intptr_t)clientData, valuePtr); } /* @@ -648,7 +648,7 @@ int offset; /* Offset of pixel size in record */ { int *valuePtr = (int *)(widgRec + offset); - return Blt_GetInt(interp, string, (int)clientData, valuePtr); + return Blt_GetInt(interp, string, (intptr_t)clientData, valuePtr); } /* --- a/generic/bltContainer.c +++ b/generic/bltContainer.c @@ -822,7 +822,7 @@ char *widgRec; /* Widget record */ int offset; /* Offset to field in structure */ { - unsigned int flags = (int)clientData; + unsigned int flags = (uintptr_t)clientData; Container *cntrPtr = (Container *)widgRec; Window *winPtr = (Window *) (widgRec + offset); Tk_Window tkAdopted; --- a/generic/bltHierbox.c +++ b/generic/bltHierbox.c @@ -2077,7 +2077,7 @@ /* Generate a unique node serial number. */ do { serial = hboxPtr->nextSerial++; - hPtr = Blt_CreateHashEntry(&(hboxPtr->nodeTable), (char *)serial, + hPtr = Blt_CreateHashEntry(&(hboxPtr->nodeTable), (char *)(intptr_t)serial, &isNew); } while (!isNew); Blt_SetHashValue(hPtr, treePtr); @@ -2372,7 +2372,7 @@ if (Tcl_GetInt(NULL, string, &serial) == TCL_OK) { Blt_HashEntry *hPtr; - hPtr = Blt_FindHashEntry(&(hboxPtr->nodeTable), (char *)serial); + hPtr = Blt_FindHashEntry(&(hboxPtr->nodeTable), (char *)(intptr_t)serial); if (hPtr != NULL) { return (Tree *) Blt_GetHashValue(hPtr); } @@ -2406,7 +2406,7 @@ int serial; /* Node table keys are integers. Convert them to strings. */ - serial = (int)Blt_GetHashKey(&(hboxPtr->nodeTable), + serial = (intptr_t)Blt_GetHashKey(&(hboxPtr->nodeTable), nodePtr->entryPtr->hashPtr); sprintf(string, "%d", serial); --- a/generic/bltUnixImage.c +++ b/generic/bltUnixImage.c @@ -574,7 +574,7 @@ destPtr = Blt_ColorImageBits(image); endPtr = destPtr + nPixels; for (/* empty */; destPtr < endPtr; destPtr++) { - hPtr = Blt_FindHashEntry(&pixelTable, (char *)destPtr->value); + hPtr = Blt_FindHashEntry(&pixelTable, (char *)(intptr_t)destPtr->value); colorPtr = (XColor *)Blt_GetHashValue(hPtr); destPtr->Red = lut[colorPtr->red >> 8]; destPtr->Green = lut[colorPtr->green >> 8]; --- a/generic/bltTable.c +++ b/generic/bltTable.c @@ -2034,7 +2034,7 @@ key = 0; /* Initialize key to bogus span */ for (node = Blt_ListFirstNode(list); node != NULL; node = Blt_ListNextNode(node)) { - key = (int)Blt_ListGetKey(node); + key = (intptr_t)Blt_ListGetKey(node); if (entryPtr->row.span <= key) { break; } @@ -2046,7 +2046,7 @@ * Create a new list (bucket) to hold entries of that size * span and and link it into the list of buckets. */ - newNode = Blt_ListCreateNode(list, (char *)entryPtr->row.span); + newNode = Blt_ListCreateNode(list, (char *)(intptr_t)entryPtr->row.span); Blt_ListSetValue(newNode, (char *)Blt_ChainCreate()); Blt_ListLinkBefore(list, newNode, node); node = newNode; @@ -2063,7 +2063,7 @@ key = 0; for (node = Blt_ListFirstNode(list); node != NULL; node = Blt_ListNextNode(node)) { - key = (int)Blt_ListGetKey(node); + key = (intptr_t)Blt_ListGetKey(node); if (entryPtr->column.span <= key) { break; } @@ -2075,7 +2075,7 @@ * Create a new list (bucket) to hold entries of that size * span and and link it into the list of buckets. */ - newNode = Blt_ListCreateNode(list, (char *)entryPtr->column.span); + newNode = Blt_ListCreateNode(list, (char *)(intptr_t)entryPtr->column.span); Blt_ListSetValue(newNode, (char *)Blt_ChainCreate()); Blt_ListLinkBefore(list, newNode, node); node = newNode; --- a/generic/bltTreeView.c +++ b/generic/bltTreeView.c @@ -1314,10 +1314,10 @@ if (isNew) { refCount = 1; } else { - refCount = (int)Blt_GetHashValue(hPtr); + refCount = (intptr_t)Blt_GetHashValue(hPtr); refCount++; } - Blt_SetHashValue(hPtr, (ClientData)refCount); + Blt_SetHashValue(hPtr, (ClientData)(intptr_t)refCount); return Blt_GetHashKey(&tvPtr->uidTable, hPtr); } @@ -1343,10 +1343,10 @@ hPtr = Blt_FindHashEntry(&tvPtr->uidTable, uid); assert(hPtr != NULL); - refCount = (int)Blt_GetHashValue(hPtr); + refCount = (intptr_t)Blt_GetHashValue(hPtr); refCount--; if (refCount > 0) { - Blt_SetHashValue(hPtr, (ClientData)refCount); + Blt_SetHashValue(hPtr, (ClientData)(intptr_t)refCount); } else { Blt_DeleteHashEntry(&tvPtr->uidTable, hPtr); } --- a/generic/bltTreeViewCmd.c +++ b/generic/bltTreeViewCmd.c @@ -516,7 +516,7 @@ if ((context == ITEM_ENTRY) || (context == ITEM_ENTRY_BUTTON) || - ((unsigned int)context >= (unsigned int)ITEM_STYLE)) { + ((uintptr_t)context >= (uintptr_t)ITEM_STYLE)) { entryPtr = Blt_GetCurrentItem(tvPtr->bindTable); } } --- a/generic/bltWinop.c +++ b/generic/bltWinop.c @@ -980,9 +980,9 @@ if (isNew) { Blt_SetHashValue(hPtr, 1); } else { - cnt = (int)Blt_GetHashValue(hPtr); + cnt = (intptr_t)Blt_GetHashValue(hPtr); cnt++; - Blt_SetHashValue(hPtr, cnt); + Blt_SetHashValue(hPtr, (intptr_t)cnt); } srcPtr++; } @@ -994,7 +994,7 @@ Tcl_Obj *objPtr = Tcl_NewStringObj(Blt_GetHashKey(&hTbl, hPtr), -1); Tcl_ListObjAppendElement(interp, listPtr, objPtr); if (iscnt) { - cnt = (int)Blt_GetHashValue(hPtr); + cnt = (intptr_t)Blt_GetHashValue(hPtr); sprintf(buf, "%d", cnt); objPtr = Tcl_NewStringObj(buf, -1); Tcl_ListObjAppendElement(interp, listPtr, objPtr); --- a/generic/bltObjConfig.c +++ b/generic/bltObjConfig.c @@ -1338,7 +1338,7 @@ if (Tcl_GetBooleanFromObj(interp, objPtr, &bool) != TCL_OK) { return TCL_ERROR; } - flag = (unsigned int)specPtr->customPtr; + flag = (uintptr_t)specPtr->customPtr; *(int *)ptr &= ~flag; if (bool) { *(int *)ptr |= flag; @@ -1639,7 +1639,7 @@ { unsigned int flag; - flag = (*(int *)ptr) & (unsigned int)specPtr->customPtr; + flag = (*(unsigned int *)ptr) & (uintptr_t)specPtr->customPtr; return Tcl_NewBooleanObj((flag != 0)); }