From 9ab7c17b2d46b1dfa2b26a297f44ace4cb2d39d1 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" <nijtmans@users.sourceforge.net> Date: Tue, 10 Jul 2018 19:22:52 +0000 Subject: Make Tk sufficiently 64-bit aware in order to withstand TIP #494 possible problems --- generic/tkBind.c | 2 -- generic/tkImgBmap.c | 4 ++-- generic/tkImgGIF.c | 16 ++++++++-------- generic/tkImgPPM.c | 14 ++++++++------ generic/tkInt.h | 6 +++--- generic/tkMain.c | 3 --- generic/tkOption.c | 1 - generic/tkUtil.c | 2 +- generic/ttk/ttkState.c | 7 ++++--- unix/Makefile.in | 2 +- unix/tkUnixKey.c | 7 ++++--- win/Makefile.in | 2 +- 12 files changed, 32 insertions(+), 34 deletions(-) diff --git a/generic/tkBind.c b/generic/tkBind.c index 295da46..05966d1 100644 --- a/generic/tkBind.c +++ b/generic/tkBind.c @@ -21,8 +21,6 @@ #else #include "tkUnixInt.h" #endif -#undef Tcl_ScanElement -#undef Tcl_ConvertElement /* * File structure: diff --git a/generic/tkImgBmap.c b/generic/tkImgBmap.c index 1a9a86e..80b1c9c 100644 --- a/generic/tkImgBmap.c +++ b/generic/tkImgBmap.c @@ -1079,10 +1079,10 @@ GetByte( Tcl_Channel chan) /* The channel we read from. */ { char buffer; - int size; + size_t size; size = Tcl_Read(chan, &buffer, 1); - if (size <= 0) { + if ((size + 1) < 2) { return EOF; } else { return buffer; diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c index ed4868b..971b42e 100644 --- a/generic/tkImgGIF.c +++ b/generic/tkImgGIF.c @@ -111,8 +111,8 @@ typedef struct { * serializing in the GIF format. */ -typedef int (WriteBytesFunc) (ClientData clientData, const char *bytes, - int byteCount); +typedef size_t (WriteBytesFunc) (ClientData clientData, const char *bytes, + size_t byteCount); /* * The format record for the GIF file format: @@ -194,7 +194,7 @@ static size_t Mread(unsigned char *dst, size_t size, size_t count, static int Mgetc(MFile *handle); static int char64(int c); static void mInit(unsigned char *string, MFile *handle, - int length); + size_t length); /* * Types, defines and variables needed to write and compress a GIF. @@ -1377,7 +1377,7 @@ static void mInit( unsigned char *string, /* string containing initial mmencoded data */ MFile *handle, /* mmdecode "file" handle */ - int length) /* Number of bytes in string */ + size_t length) /* Number of bytes in string */ { handle->data = string; handle->state = 0; @@ -1658,22 +1658,22 @@ StringWriteGIF( return result; } -static int +static size_t WriteToChannel( ClientData clientData, const char *bytes, - int byteCount) + size_t byteCount) { Tcl_Channel handle = clientData; return Tcl_Write(handle, bytes, byteCount); } -static int +static size_t WriteToByteArray( ClientData clientData, const char *bytes, - int byteCount) + size_t byteCount) { Tcl_Obj *objPtr = clientData; Tcl_Obj *tmpObj = Tcl_NewByteArrayObj((unsigned char *) bytes, byteCount); diff --git a/generic/tkImgPPM.c b/generic/tkImgPPM.c index 6f084f0..6dd92a2 100644 --- a/generic/tkImgPPM.c +++ b/generic/tkImgPPM.c @@ -141,7 +141,8 @@ FileReadPPM( * image being read. */ { int fileWidth, fileHeight, maxIntensity; - int nLines, nBytes, h, type, count, bytesPerChannel = 1; + int nLines, h, type, bytesPerChannel = 1; + size_t nBytes, count; unsigned char *pixelPtr; Tk_PhotoImageBlock block; @@ -285,7 +286,8 @@ FileWritePPM( Tk_PhotoImageBlock *blockPtr) { Tcl_Channel chan; - int w, h, greenOffset, blueOffset, nBytes; + int w, h, greenOffset, blueOffset; + size_t nBytes; unsigned char *pixelPtr, *pixLinePtr; char header[16 + TCL_INTEGER_SPACE * 2]; @@ -315,16 +317,16 @@ FileWritePPM( if ((greenOffset == 1) && (blueOffset == 2) && (blockPtr->pixelSize == 3) && (blockPtr->pitch == (blockPtr->width * 3))) { nBytes = blockPtr->height * blockPtr->pitch; - if (Tcl_Write(chan, (char *) pixLinePtr, nBytes) != nBytes) { + if ((size_t)Tcl_Write(chan, (char *) pixLinePtr, nBytes) != nBytes) { goto writeerror; } } else { for (h = blockPtr->height; h > 0; h--) { pixelPtr = pixLinePtr; for (w = blockPtr->width; w > 0; w--) { - if ( Tcl_Write(chan,(char *)&pixelPtr[0], 1) == -1 || - Tcl_Write(chan,(char *)&pixelPtr[greenOffset],1)==-1 || - Tcl_Write(chan,(char *)&pixelPtr[blueOffset],1) ==-1) { + if ((size_t)Tcl_Write(chan,(char *)&pixelPtr[0], 1) == (size_t)-1 || + (size_t)Tcl_Write(chan,(char *)&pixelPtr[greenOffset],1)==(size_t)-1 || + (size_t)Tcl_Write(chan,(char *)&pixelPtr[blueOffset],1) ==(size_t)-1) { goto writeerror; } pixelPtr += blockPtr->pixelSize; diff --git a/generic/tkInt.h b/generic/tkInt.h index 12c5f88..d21b14f 100644 --- a/generic/tkInt.h +++ b/generic/tkInt.h @@ -824,13 +824,13 @@ typedef struct TkWindow { */ typedef struct { - XKeyEvent keyEvent; /* The real event from X11. */ - char *charValuePtr; /* A pointer to a string that holds the key's + XKeyEvent keyEvent; /* The real event from X11. */ + char *charValuePtr; /* A pointer to a string that holds the key's * %A substitution text (before backslash * adding), or NULL if that has not been * computed yet. If non-NULL, this string was * allocated with ckalloc(). */ - int charValueLen; /* Length of string in charValuePtr when that + size_t charValueLen; /* Length of string in charValuePtr when that * is non-NULL. */ KeySym keysym; /* Key symbol computed after input methods * have been invoked */ diff --git a/generic/tkMain.c b/generic/tkMain.c index 354ff6d..5ee893c 100644 --- a/generic/tkMain.c +++ b/generic/tkMain.c @@ -38,9 +38,6 @@ #else # include <stdlib.h> #endif -#undef Tcl_Gets -#undef Tcl_WriteObj -#undef Tcl_WriteChars extern int TkCygwinMainEx(int, char **, Tcl_AppInitProc *, Tcl_Interp *); diff --git a/generic/tkOption.c b/generic/tkOption.c index c837a50..6c09150 100644 --- a/generic/tkOption.c +++ b/generic/tkOption.c @@ -13,7 +13,6 @@ */ #include "tkInt.h" -#undef Tcl_ReadChars /* * The option database is stored as one tree for each main window. Each name diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 16ec154..1db7684 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/unix/Makefile.in b/unix/Makefile.in index 315fcfc..09de560 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -137,7 +137,7 @@ CFLAGS_OPTIMIZE = @CFLAGS_OPTIMIZE@ #CFLAGS = $(CFLAGS_DEBUG) #CFLAGS = $(CFLAGS_OPTIMIZE) #CFLAGS = $(CFLAGS_DEBUG) $(CFLAGS_OPTIMIZE) -CFLAGS = @CFLAGS_DEFAULT@ @CFLAGS@ -DTCL_USE_INT_RETURN +CFLAGS = @CFLAGS_DEFAULT@ @CFLAGS@ # Flags to pass to the linker LDFLAGS_DEBUG = @LDFLAGS_DEBUG@ diff --git a/unix/tkUnixKey.c b/unix/tkUnixKey.c index d8aa5ab..dc6fd0d 100644 --- a/unix/tkUnixKey.c +++ b/unix/tkUnixKey.c @@ -110,7 +110,8 @@ TkpGetString( XEvent *eventPtr, /* X keyboard event. */ Tcl_DString *dsPtr) /* Initialized, empty string to hold result. */ { - int len, mincode, maxcode; + size_t len; + int mincode, maxcode; Tcl_DString buf; TkKeyEvent *kePtr = (TkKeyEvent *) eventPtr; @@ -121,7 +122,7 @@ TkpGetString( if (kePtr->charValuePtr != NULL) { Tcl_DStringSetLength(dsPtr, kePtr->charValueLen); memcpy(Tcl_DStringValue(dsPtr), kePtr->charValuePtr, - (unsigned) kePtr->charValueLen+1); + kePtr->charValueLen+1); return Tcl_DStringValue(dsPtr); } @@ -246,7 +247,7 @@ TkpGetString( done: kePtr->charValuePtr = ckalloc(len + 1); kePtr->charValueLen = len; - memcpy(kePtr->charValuePtr, Tcl_DStringValue(dsPtr), (unsigned) len + 1); + memcpy(kePtr->charValuePtr, Tcl_DStringValue(dsPtr), len + 1); return Tcl_DStringValue(dsPtr); } diff --git a/win/Makefile.in b/win/Makefile.in index 5a4a273..3c1c9e3 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -170,7 +170,7 @@ LDFLAGS_OPTIMIZE = @LDFLAGS_OPTIMIZE@ #CFLAGS = $(CFLAGS_DEBUG) #CFLAGS = $(CFLAGS_OPTIMIZE) #CFLAGS = $(CFLAGS_DEBUG) $(CFLAGS_OPTIMIZE) -CFLAGS = @CFLAGS@ @CFLAGS_DEFAULT@ -DUNICODE -D_UNICODE -D_ATL_XP_TARGETING -DTCL_USE_INT_RETURN +CFLAGS = @CFLAGS@ @CFLAGS_DEFAULT@ -DUNICODE -D_UNICODE -D_ATL_XP_TARGETING # Special compiler flags to use when building man2tcl on Windows. MAN2TCLFLAGS = @MAN2TCLFLAGS@ -- cgit v0.12