From 254025c6d682cfde6e1cada371c419af7c60087b Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 30 Mar 2025 08:41:50 +0000 Subject: Fix some -Wconversion warnings --- generic/tclFileName.c | 4 ++-- unix/tclSelectNotfy.c | 11 +++++++---- unix/tclUnixChan.c | 22 +++++++++++----------- unix/tclUnixCompat.c | 26 +++++++++++++------------- unix/tclUnixFCmd.c | 22 +++++++++++----------- unix/tclUnixFile.c | 24 ++++++++++++------------ unix/tclUnixPipe.c | 17 +++++++++-------- unix/tclUnixSock.c | 14 +++++++------- win/tclWinDde.c | 4 ++-- win/tclWinReg.c | 4 ++-- win/tclWinTime.c | 6 +++--- 11 files changed, 79 insertions(+), 75 deletions(-) diff --git a/generic/tclFileName.c b/generic/tclFileName.c index c92951a..068a041 100644 --- a/generic/tclFileName.c +++ b/generic/tclFileName.c @@ -1966,8 +1966,8 @@ DoGlob( Tcl_GlobTypeData *types) /* List object containing list of acceptable * types. May be NULL. */ { - int baseLength, quoted; - int result = TCL_OK; + Tcl_Size baseLength; + int quoted, result = TCL_OK; char *name, *p, *openBrace, *closeBrace, *firstSpecialChar; Tcl_Obj *joinedPtr; diff --git a/unix/tclSelectNotfy.c b/unix/tclSelectNotfy.c index bede898..58b5c3f 100644 --- a/unix/tclSelectNotfy.c +++ b/unix/tclSelectNotfy.c @@ -768,15 +768,18 @@ TclpWaitForEvent( if (!tsdPtr->eventReady) { #ifdef __CYGWIN__ if (!PeekMessageW(&msg, NULL, 0, 0, 0)) { - unsigned int timeout; + long long timeout; if (timePtr) { timeout = timePtr->sec * 1000 + timePtr->usec / 1000; + if (timeout > UINT_MAX) { + timeout = UINT_MAX; + } } else { - timeout = 0xFFFFFFFF; + timeout = UINT_MAX; } pthread_mutex_unlock(¬ifierMutex); - MsgWaitForMultipleObjects(1, &tsdPtr->event, 0, timeout, 1279); + MsgWaitForMultipleObjects(1, &tsdPtr->event, 0, (unsigned int)timeout, 1279); pthread_mutex_lock(¬ifierMutex); } #else /* !__CYGWIN__ */ @@ -806,7 +809,7 @@ TclpWaitForEvent( unsigned int result = GetMessageW(&msg, NULL, 0, 0); if (result == 0) { - PostQuitMessage(msg.wParam); + PostQuitMessage((int)msg.wParam); /* What to do here? */ } else if (result != (unsigned int) -1) { TranslateMessage(&msg); diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 75584fe..4b184f5 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -266,7 +266,7 @@ FileInputProc( int *errorCodePtr) /* Where to store error code. */ { FileState *fsPtr = (FileState *)instanceData; - int bytesRead; /* How many bytes were actually read from the + ssize_t bytesRead; /* How many bytes were actually read from the * input device? */ *errorCodePtr = 0; @@ -286,7 +286,7 @@ FileInputProc( *errorCodePtr = errno; return -1; } - return bytesRead; + return (int)bytesRead; } /* @@ -315,7 +315,7 @@ FileOutputProc( int *errorCodePtr) /* Where to store error code. */ { FileState *fsPtr = (FileState *)instanceData; - int written; + ssize_t written; *errorCodePtr = 0; @@ -330,7 +330,7 @@ FileOutputProc( } written = write(fsPtr->fd, buf, toWrite); if (written >= 0) { - return written; + return (int)written; } *errorCodePtr = errno; return -1; @@ -659,7 +659,7 @@ FileGetOptionProc( { FileState *fsPtr = (FileState *)instanceData; int valid = 0; /* Flag if valid option parsed. */ - int len; + size_t len; if (optionName == NULL) { len = 0; @@ -860,18 +860,18 @@ TtySetOptionProc( iostate.c_cc[VSTOP] = argv[1][0]; if (argv[0][0] & 0x80 || argv[1][0] & 0x80) { Tcl_UniChar character = 0; - int charLen; + Tcl_Size charLen; charLen = TclUtfToUniChar(argv[0], &character); if ((character > 0xFF) || argv[0][charLen]) { goto badXchar; } - iostate.c_cc[VSTART] = character; + iostate.c_cc[VSTART] = (cc_t)character; charLen = TclUtfToUniChar(argv[1], &character); if ((character > 0xFF) || argv[1][charLen]) { goto badXchar; } - iostate.c_cc[VSTOP] = character; + iostate.c_cc[VSTOP] = (cc_t)character; } Tcl_Free(argv); @@ -891,7 +891,7 @@ TtySetOptionProc( return TCL_ERROR; } iostate.c_cc[VMIN] = 0; - iostate.c_cc[VTIME] = (msec==0) ? 0 : (msec<100) ? 1 : (msec+50)/100; + iostate.c_cc[VTIME] = (msec==0) ? 0 : (msec<100) ? 1 : (cc_t)((msec+50)/100); tcsetattr(fsPtr->fileState.fd, TCSADRAIN, &iostate); return TCL_OK; } @@ -1906,7 +1906,7 @@ Tcl_MakeFileChannel( { TtyState *fsPtr; char channelName[16 + TCL_INTEGER_SPACE]; - int fd = PTR2INT(handle); + int fd = (int)PTR2INT(handle); const Tcl_ChannelType *channelTypePtr; Tcl_StatBuf buf; @@ -2112,7 +2112,7 @@ Tcl_GetOpenFile( || (strcmp(chanTypePtr->typeName, "pipe") == 0)) { if (Tcl_GetChannelHandle(chan, (forWriting ? TCL_WRITABLE : TCL_READABLE), &data) == TCL_OK) { - fd = PTR2INT(data); + fd = (int)PTR2INT(data); /* * The call to fdopen below is probably dangerous, since it will diff --git a/unix/tclUnixCompat.c b/unix/tclUnixCompat.c index def69fa..7120b86 100644 --- a/unix/tclUnixCompat.c +++ b/unix/tclUnixCompat.c @@ -107,11 +107,11 @@ static int CopyGrp(struct group *tgtPtr, char *buf, int buflen); static int CopyPwd(struct passwd *tgtPtr, char *buf, int buflen); #endif -static int CopyArray(char **src, int elsize, char *buf, - int buflen); +static size_t CopyArray(char **src, int elsize, char *buf, + size_t buflen); static int CopyHostent(struct hostent *tgtPtr, char *buf, - int buflen); -static int CopyString(const char *src, char *buf, int buflen); + size_t buflen); +static size_t CopyString(const char *src, char *buf, size_t buflen); #endif @@ -754,10 +754,10 @@ static int CopyHostent( struct hostent *tgtPtr, char *buf, - int buflen) + size_t buflen) { char *p = buf; - int copied, len = 0; + Tcl_Size copied, len = 0; copied = CopyString(tgtPtr->h_name, p, buflen - len); if (copied == -1) { @@ -875,16 +875,16 @@ CopyPwd( */ #ifdef NEED_COPYARRAY -static int +static size_t CopyArray( char **src, /* Array of elements to copy. */ int elsize, /* Size of each element, or -1 to indicate * that they are C strings of dynamic * length. */ char *buf, /* Buffer to copy into. */ - int buflen) /* Size of buffer. */ + size_t buflen) /* Size of buffer. */ { - int i, j, len = 0; + size_t i, j, len = 0; char *p, **newBuffer; if (src == NULL) { @@ -905,7 +905,7 @@ CopyArray( p = buf + len; for (j = 0; j < i; j++) { - int sz = (elsize<0 ? (int) strlen(src[j]) + 1 : elsize); + size_t sz = (elsize<0 ? strlen(src[j]) + 1 : (size_t)elsize); len += sz; if (len > buflen) { @@ -939,13 +939,13 @@ CopyArray( */ #ifdef NEED_COPYSTRING -static int +static size_t CopyString( const char *src, /* String to copy. */ char *buf, /* Buffer to copy into. */ - int buflen) /* Size of buffer. */ + size_t buflen) /* Size of buffer. */ { - int len = 0; + size_t len = 0; if (src != NULL) { len = strlen(src) + 1; diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c index db45999..9bc9da6 100644 --- a/unix/tclUnixFCmd.c +++ b/unix/tclUnixFCmd.c @@ -452,11 +452,11 @@ DoCopyFile( } } - switch ((int) (statBufPtr->st_mode & S_IFMT)) { + switch ((int)(statBufPtr->st_mode & S_IFMT)) { #ifndef DJGPP case S_IFLNK: { char linkBuf[MAXPATHLEN+1]; - int length; + ssize_t length; length = readlink(src, linkBuf, MAXPATHLEN); /* INTL: Native. */ if (length == -1) { @@ -1069,7 +1069,7 @@ TraverseUnixTree( while ((ent = fts_read(fts)) != NULL) { unsigned short info = ent->fts_info; char *path = ent->fts_path + sourceLen; - unsigned short pathlen = ent->fts_pathlen - sourceLen; + Tcl_Size pathlen = ent->fts_pathlen - sourceLen; int type; Tcl_StatBuf *statBufPtr = NULL; @@ -1626,7 +1626,7 @@ SetPermissionsAttribute( int result = TCL_ERROR; const char *native; const char *modeStringPtr = TclGetString(attributePtr); - int scanned = TclParseAllWhiteSpace(modeStringPtr, -1); + Tcl_Size scanned = TclParseAllWhiteSpace(modeStringPtr, -1); /* * First supply support for octal number format @@ -1978,7 +1978,7 @@ TclpObjNormalizePath( * routine should be reviewed and cleaed up. */ } else { - nextCheckpoint = lastDir - path; + nextCheckpoint = (int)(lastDir - path); goto wholeStringOk; } } @@ -2021,7 +2021,7 @@ TclpObjNormalizePath( * Assign the end of the current component to nextCheckpoint */ - nextCheckpoint = currentPathEndPosition - path; + nextCheckpoint = (int)(currentPathEndPosition - path); } else if (cur == 0) { /* * The end of the string. @@ -2096,7 +2096,7 @@ TclpObjNormalizePath( * Append the remaining path components. */ - int normLen = Tcl_DStringLength(&ds); + Tcl_Size normLen = Tcl_DStringLength(&ds); Tcl_DStringAppend(&ds, path + nextCheckpoint, pathLen - nextCheckpoint); @@ -2106,13 +2106,13 @@ TclpObjNormalizePath( * been processed */ - nextCheckpoint = normLen + 1; + nextCheckpoint = (int)normLen + 1; } else { /* * We recognise the whole string. */ - nextCheckpoint = Tcl_DStringLength(&ds); + nextCheckpoint = (int)Tcl_DStringLength(&ds); } Tcl_SetStringObj(pathPtr, Tcl_DStringValue(&ds), @@ -2214,7 +2214,7 @@ TclUnixOpenTemporaryFile( return -1; } TclDStringAppendDString(&templ, &tmp); - fd = mkstemps(Tcl_DStringValue(&templ), Tcl_DStringLength(&tmp)); + fd = mkstemps(Tcl_DStringValue(&templ), (int)Tcl_DStringLength(&tmp)); Tcl_DStringFree(&tmp); } else #endif @@ -2387,7 +2387,7 @@ static WCHAR * winPathFromObj( Tcl_Obj *fileName) { - size_t size; + int size; const char *native = (const char *)Tcl_FSGetNativePath(fileName); WCHAR *winPath; diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index 2b0b5b0..97acb24 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -1237,13 +1237,13 @@ TclOSfstat( Tcl_StatBuf *statBuf = (Tcl_StatBuf *)cygstat; int result = fstat(fd, &buf); - statBuf->st_mode = buf.st_mode; - statBuf->st_ino = buf.st_ino; + statBuf->st_mode = (unsigned short)buf.st_mode; + statBuf->st_ino = (unsigned short)buf.st_ino; statBuf->st_dev = buf.st_dev; statBuf->st_rdev = buf.st_rdev; statBuf->st_nlink = buf.st_nlink; - statBuf->st_uid = buf.st_uid; - statBuf->st_gid = buf.st_gid; + statBuf->st_uid = (short)buf.st_uid; + statBuf->st_gid = (short)buf.st_gid; statBuf->st_size = buf.st_size; statBuf->st_atime = buf.st_atime; statBuf->st_mtime = buf.st_mtime; @@ -1260,13 +1260,13 @@ TclOSstat( Tcl_StatBuf *statBuf = (Tcl_StatBuf *)cygstat; int result = stat(name, &buf); - statBuf->st_mode = buf.st_mode; - statBuf->st_ino = buf.st_ino; + statBuf->st_mode = (unsigned short)buf.st_mode; + statBuf->st_ino = (unsigned short)buf.st_ino; statBuf->st_dev = buf.st_dev; statBuf->st_rdev = buf.st_rdev; statBuf->st_nlink = buf.st_nlink; - statBuf->st_uid = buf.st_uid; - statBuf->st_gid = buf.st_gid; + statBuf->st_uid = (short)buf.st_uid; + statBuf->st_gid = (short)buf.st_gid; statBuf->st_size = buf.st_size; statBuf->st_atime = buf.st_atime; statBuf->st_mtime = buf.st_mtime; @@ -1283,13 +1283,13 @@ TclOSlstat( Tcl_StatBuf *statBuf = (Tcl_StatBuf *)cygstat; int result = lstat(name, &buf); - statBuf->st_mode = buf.st_mode; - statBuf->st_ino = buf.st_ino; + statBuf->st_mode = (unsigned short)buf.st_mode; + statBuf->st_ino = (unsigned short)buf.st_ino; statBuf->st_dev = buf.st_dev; statBuf->st_rdev = buf.st_rdev; statBuf->st_nlink = buf.st_nlink; - statBuf->st_uid = buf.st_uid; - statBuf->st_gid = buf.st_gid; + statBuf->st_uid = (short)buf.st_uid; + statBuf->st_gid = (short)buf.st_gid; statBuf->st_size = buf.st_size; statBuf->st_atime = buf.st_atime; statBuf->st_mtime = buf.st_mtime; diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index 8d4a6b0..ca452d7 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -34,8 +34,8 @@ * the same as NULL. */ -#define MakeFile(fd) ((TclFile) INT2PTR(((int) (fd)) + 1)) -#define GetFd(file) (PTR2INT(file) - 1) +#define MakeFile(fd) ((TclFile)INT2PTR((fd) + 1)) +#define GetFd(file) ((int)PTR2INT(file) - 1) /* * This structure describes per-instance state of a pipe based channel. @@ -426,7 +426,8 @@ TclpCreateProcess( * process. */ { TclFile errPipeIn, errPipeOut; - int count, status, fd; + ssize_t count; + int status, fd; char errSpace[200 + TCL_INTEGER_SPACE]; Tcl_DString *volatile dsArray; char **volatile newArgv; @@ -630,7 +631,7 @@ TclpCreateProcess( char *end; errSpace[count] = 0; - errno = strtol(errSpace, &end, 10); + errno = (int)strtol(errSpace, &end, 10); Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s: %s", end, Tcl_PosixError(interp))); goto error; @@ -1147,7 +1148,7 @@ PipeInputProc( int *errorCodePtr) /* Where to store error code. */ { PipeState *psPtr = (PipeState *)instanceData; - int bytesRead; /* How many bytes were actually read from the + ssize_t bytesRead; /* How many bytes were actually read from the * input device? */ *errorCodePtr = 0; @@ -1168,7 +1169,7 @@ PipeInputProc( *errorCodePtr = errno; return -1; } - return bytesRead; + return (int)bytesRead; } /* @@ -1197,7 +1198,7 @@ PipeOutputProc( int *errorCodePtr) /* Where to store error code. */ { PipeState *psPtr = (PipeState *)instanceData; - int written; + ssize_t written; *errorCodePtr = 0; @@ -1214,7 +1215,7 @@ PipeOutputProc( *errorCodePtr = errno; return -1; } - return written; + return (int)written; } /* diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index f2b15b2..cfdf98d 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -508,7 +508,7 @@ TcpInputProc( int *errorCodePtr) /* Where to store error code. */ { TcpState *statePtr = (TcpState *)instanceData; - int bytesRead; + ssize_t bytesRead; *errorCodePtr = 0; if (WaitForConnect(statePtr, errorCodePtr) != 0) { @@ -516,7 +516,7 @@ TcpInputProc( } bytesRead = recv(statePtr->fds.fd, buf, bufSize, 0); if (bytesRead >= 0) { - return bytesRead; + return (int)bytesRead; } if (errno == ECONNRESET) { /* @@ -558,7 +558,7 @@ TcpOutputProc( int *errorCodePtr) /* Where to store error code. */ { TcpState *statePtr = (TcpState *)instanceData; - int written; + ssize_t written; *errorCodePtr = 0; if (WaitForConnect(statePtr, errorCodePtr) != 0) { @@ -567,7 +567,7 @@ TcpOutputProc( written = send(statePtr->fds.fd, buf, toWrite, 0); if (written >= 0) { - return written; + return (int)written; } *errorCodePtr = errno; return -1; @@ -1607,7 +1607,7 @@ TclpMakeTcpClientChannelMode( statePtr = (TcpState *)Tcl_Alloc(sizeof(TcpState)); memset(statePtr, 0, sizeof(TcpState)); - statePtr->fds.fd = PTR2INT(sock); + statePtr->fds.fd = (int)PTR2INT(sock); statePtr->flags = 0; snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, PTR2INT(statePtr)); @@ -1768,8 +1768,8 @@ Tcl_OpenTcpServerEx( */ if (port == 0 && chosenport != 0) { - ((struct sockaddr_in *) addrPtr->ai_addr)->sin_port = - htons(chosenport); + ((struct sockaddr_in *)addrPtr->ai_addr)->sin_port = + htons((uint16_t)chosenport); } #ifdef IPV6_V6ONLY diff --git a/win/tclWinDde.c b/win/tclWinDde.c index 12a10e6..17643e3 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -1334,8 +1334,8 @@ DdeObjCmd( }; int index, argIndex; - Tcl_Size length, i; - int flags = 0, result = TCL_OK, firstArg = 0; + Tcl_Size length, i, firstArg = 0; + int flags = 0, result = TCL_OK; HSZ ddeService = NULL, ddeTopic = NULL, ddeItem = NULL, ddeCookie = NULL; HDDEDATA ddeData = NULL, ddeItemData = NULL, ddeReturn; HCONV hConv = NULL; diff --git a/win/tclWinReg.c b/win/tclWinReg.c index 59de335..7b6302c 100644 --- a/win/tclWinReg.c +++ b/win/tclWinReg.c @@ -808,7 +808,7 @@ GetValue( * HKEY_PERFORMANCE_DATA */ - length = Tcl_DStringLength(&data) * (2 / sizeof(WCHAR)); + length = (DWORD)(Tcl_DStringLength(&data) * (2 / sizeof(WCHAR))); Tcl_DStringSetLength(&data, length * sizeof(WCHAR)); result = RegQueryValueExW(key, nativeValue, NULL, &type, (BYTE *) Tcl_DStringValue(&data), &length); @@ -1501,7 +1501,7 @@ AppendSystemError( Tcl_Interp *interp, /* Current interpreter. */ DWORD error) /* Result code from error. */ { - int length; + Tcl_Size length; WCHAR *tMsgPtr, **tMsgPtrPtr = &tMsgPtr; const char *msg; char id[TCL_INTEGER_SPACE], msgBuf[24 + TCL_INTEGER_SPACE]; diff --git a/win/tclWinTime.c b/win/tclWinTime.c index 8cc4489..c0d2b2e 100644 --- a/win/tclWinTime.c +++ b/win/tclWinTime.c @@ -260,7 +260,7 @@ TclpGetWideClicks(void) if (QueryPerformanceFrequency(&perfCounterFreq)) { wideClick.perfCounter = 1; - wideClick.microsecsScale = 1000000.0 / perfCounterFreq.QuadPart; + wideClick.microsecsScale = 1000000.0 / (double)perfCounterFreq.QuadPart; } else { /* fallback using microseconds */ wideClick.perfCounter = 0; @@ -384,7 +384,7 @@ Tcl_GetTime( if (IsTimeNative() && (usecSincePosixEpoch = NativeGetMicroseconds())) { timePtr->sec = usecSincePosixEpoch / 1000000; - timePtr->usec = usecSincePosixEpoch % 1000000; + timePtr->usec = (long)(usecSincePosixEpoch % 1000000); } else { GetTime(timePtr); } @@ -687,7 +687,7 @@ NativeGetTime( usecSincePosixEpoch = NativeGetMicroseconds(); if (usecSincePosixEpoch) { timePtr->sec = usecSincePosixEpoch / 1000000; - timePtr->usec = usecSincePosixEpoch % 1000000; + timePtr->usec = (long)(usecSincePosixEpoch % 1000000); } else { /* * High resolution timer is not available. Just use ftime. -- cgit v0.12