summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-03-30 15:19:44 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-03-30 15:19:44 (GMT)
commit191fecdc87592dfea94718bc716551c72f072c33 (patch)
tree4aa12b60fc6ad7ca4c19658d774dee4326ad165b /win
parent784535a35c779f46886fe9a880b706c979efdd77 (diff)
downloadtcl-191fecdc87592dfea94718bc716551c72f072c33.zip
tcl-191fecdc87592dfea94718bc716551c72f072c33.tar.gz
tcl-191fecdc87592dfea94718bc716551c72f072c33.tar.bz2
Fix [0cb3554903]: macOS 13 SDK deprecates sprintf(). But better not use it on other platforms either.
Diffstat (limited to 'win')
-rw-r--r--win/tclWinChan.c5
-rw-r--r--win/tclWinConsole.c17
-rw-r--r--win/tclWinFCmd.c18
-rw-r--r--win/tclWinFile.c2
-rw-r--r--win/tclWinInit.c70
-rw-r--r--win/tclWinInt.h2
-rw-r--r--win/tclWinPipe.c22
-rw-r--r--win/tclWinReg.c4
-rw-r--r--win/tclWinSerial.c27
-rw-r--r--win/tclWinSock.c8
-rw-r--r--win/tclWinThrd.c14
11 files changed, 71 insertions, 118 deletions
diff --git a/win/tclWinChan.c b/win/tclWinChan.c
index 3a3eba4..72a71ab 100644
--- a/win/tclWinChan.c
+++ b/win/tclWinChan.c
@@ -98,6 +98,9 @@ static int FileTruncateProc(ClientData instanceData,
Tcl_WideInt length);
static DWORD FileGetType(HANDLE handle);
static int NativeIsComPort(const WCHAR *nativeName);
+static Tcl_Channel TclWinOpenFileChannel(HANDLE handle, char *channelName,
+ int permissions, int appendMode);
+
/*
* This structure describes the channel type structure for file based IO.
*/
@@ -1382,7 +1385,7 @@ TclWinOpenFileChannel(
infoPtr->flags = appendMode;
infoPtr->handle = handle;
infoPtr->dirty = 0;
- sprintf(channelName, "file%" TCL_Z_MODIFIER "x", (size_t) infoPtr);
+ snprintf(channelName, 16 + TCL_INTEGER_SPACE, "file%" TCL_Z_MODIFIER "x", (size_t) infoPtr);
infoPtr->channel = Tcl_CreateChannel(&fileChannelType, channelName,
infoPtr, permissions);
diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c
index 41a05ad..b9b81f8 100644
--- a/win/tclWinConsole.c
+++ b/win/tclWinConsole.c
@@ -460,7 +460,7 @@ ConsoleCheckProc(
}
if (needEvent) {
- ConsoleEvent *evPtr = ckalloc(sizeof(ConsoleEvent));
+ ConsoleEvent *evPtr = (ConsoleEvent *)ckalloc(sizeof(ConsoleEvent));
infoPtr->flags |= CONSOLE_PENDING;
evPtr->header.proc = ConsoleEventProc;
@@ -492,7 +492,7 @@ ConsoleBlockModeProc(
int mode) /* TCL_MODE_BLOCKING or
* TCL_MODE_NONBLOCKING. */
{
- ConsoleInfo *infoPtr = instanceData;
+ ConsoleInfo *infoPtr = (ConsoleInfo *)instanceData;
/*
* Consoles on Windows can not be switched between blocking and
@@ -531,7 +531,7 @@ ConsoleCloseProc(
ClientData instanceData, /* Pointer to ConsoleInfo structure. */
Tcl_Interp *interp) /* For error reporting. */
{
- ConsoleInfo *consolePtr = instanceData;
+ ConsoleInfo *consolePtr = (ConsoleInfo *)instanceData;
int errorCode = 0;
ConsoleInfo *infoPtr, **nextPtrPtr;
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
@@ -650,7 +650,7 @@ ConsoleInputProc(
* buffer? */
int *errorCode) /* Where to store error code. */
{
- ConsoleInfo *infoPtr = instanceData;
+ ConsoleInfo *infoPtr = (ConsoleInfo *)instanceData;
DWORD count, bytesRead = 0;
int result;
@@ -1121,7 +1121,7 @@ ConsoleReaderThread(
{
TclPipeThreadInfo *pipeTI = (TclPipeThreadInfo *)arg;
ConsoleInfo *infoPtr = NULL; /* access info only after success init/wait */
- HANDLE *handle = NULL;
+ HANDLE handle = NULL;
ConsoleThreadInfo *threadInfo = NULL;
int done = 0;
@@ -1218,7 +1218,7 @@ ConsoleWriterThread(
{
TclPipeThreadInfo *pipeTI = (TclPipeThreadInfo *)arg;
ConsoleInfo *infoPtr = NULL; /* access info only after success init/wait */
- HANDLE *handle = NULL;
+ HANDLE handle = NULL;
ConsoleThreadInfo *threadInfo = NULL;
DWORD count, toWrite;
char *buf;
@@ -1311,7 +1311,6 @@ TclWinOpenConsoleChannel(
char *channelName,
int permissions)
{
- char encoding[4 + TCL_INTEGER_SPACE];
ConsoleInfo *infoPtr;
DWORD modes;
@@ -1328,8 +1327,6 @@ TclWinOpenConsoleChannel(
infoPtr->handle = handle;
infoPtr->channel = (Tcl_Channel) NULL;
- wsprintfA(encoding, "cp%d", GetConsoleCP());
-
infoPtr->threadId = Tcl_GetCurrentThread();
/*
@@ -1338,7 +1335,7 @@ TclWinOpenConsoleChannel(
* for instance).
*/
- sprintf(channelName, "file%" TCL_Z_MODIFIER "x", (size_t) infoPtr);
+ snprintf(channelName, TCL_INTEGER_SPACE + 4, "file%" TCL_Z_MODIFIER "x", (size_t) infoPtr);
infoPtr->channel = Tcl_CreateChannel(&consoleChannelType, channelName,
infoPtr, permissions);
diff --git a/win/tclWinFCmd.c b/win/tclWinFCmd.c
index 86fea7e..595f6b7 100644
--- a/win/tclWinFCmd.c
+++ b/win/tclWinFCmd.c
@@ -145,8 +145,8 @@ TclpObjRenameFile(
Tcl_Obj *srcPathPtr,
Tcl_Obj *destPathPtr)
{
- return DoRenameFile(Tcl_FSGetNativePath(srcPathPtr),
- Tcl_FSGetNativePath(destPathPtr));
+ return DoRenameFile((WCHAR *)Tcl_FSGetNativePath(srcPathPtr),
+ (WCHAR *)Tcl_FSGetNativePath(destPathPtr));
}
static int
@@ -534,8 +534,8 @@ TclpObjCopyFile(
Tcl_Obj *srcPathPtr,
Tcl_Obj *destPathPtr)
{
- return DoCopyFile(Tcl_FSGetNativePath(srcPathPtr),
- Tcl_FSGetNativePath(destPathPtr));
+ return DoCopyFile((WCHAR *)Tcl_FSGetNativePath(srcPathPtr),
+ (WCHAR *)Tcl_FSGetNativePath(destPathPtr));
}
static int
@@ -749,7 +749,7 @@ TclpDeleteFile(
const void *nativePath) /* Pathname of file to be removed (native). */
{
DWORD attr;
- const WCHAR *path = nativePath;
+ const WCHAR *path = (const WCHAR *)nativePath;
/*
* The DeleteFile API acts differently under Win95/98 and NT WRT NULL and
@@ -854,7 +854,7 @@ int
TclpObjCreateDirectory(
Tcl_Obj *pathPtr)
{
- return DoCreateDirectory(Tcl_FSGetNativePath(pathPtr));
+ return DoCreateDirectory((WCHAR *)Tcl_FSGetNativePath(pathPtr));
}
static int
@@ -988,7 +988,7 @@ TclpObjRemoveDirectory(
ret = DoRemoveDirectory(&native, recursive, &ds);
Tcl_DStringFree(&native);
} else {
- ret = DoRemoveJustDirectory(Tcl_FSGetNativePath(pathPtr), 0, &ds);
+ ret = DoRemoveJustDirectory((WCHAR *)Tcl_FSGetNativePath(pathPtr), 0, &ds);
}
if (ret != TCL_OK) {
@@ -1506,7 +1506,7 @@ GetWinFileAttributes(
const WCHAR *nativeName;
int attr;
- nativeName = Tcl_FSGetNativePath(fileName);
+ nativeName = (WCHAR *)Tcl_FSGetNativePath(fileName);
result = GetFileAttributesW(nativeName);
if (result == 0xFFFFFFFF) {
@@ -1833,7 +1833,7 @@ SetWinFileAttributes(
int yesNo, result;
const WCHAR *nativeName;
- nativeName = Tcl_FSGetNativePath(fileName);
+ nativeName = (WCHAR *)Tcl_FSGetNativePath(fileName);
fileAttributes = old = GetFileAttributesW(nativeName);
if (fileAttributes == 0xFFFFFFFF) {
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index a6f27c9..efd2104 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -946,7 +946,7 @@ TclpMatchInDirectory(
WIN32_FILE_ATTRIBUTE_DATA data;
const char *str = Tcl_GetStringFromObj(norm,&len);
- native = Tcl_FSGetNativePath(pathPtr);
+ native = (WCHAR *)Tcl_FSGetNativePath(pathPtr);
if (GetFileAttributesExW(native,
GetFileExInfoStandard, &data) != TRUE) {
diff --git a/win/tclWinInit.c b/win/tclWinInit.c
index 582c700..3aadf7a 100644
--- a/win/tclWinInit.c
+++ b/win/tclWinInit.c
@@ -4,7 +4,7 @@
* Contains the Windows-specific interpreter initialization functions.
*
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
- * Copyright (c) 1998-1999 by Scriptics Corporation.
+ * Copyright (c) 1998-1999 Scriptics Corporation.
* All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution of
@@ -64,12 +64,6 @@ static ProcessGlobalValue sourceLibraryDir =
{0, 0, NULL, NULL, InitializeSourceLibraryDir, NULL, NULL};
static void AppendEnvironment(Tcl_Obj *listPtr, const char *lib);
-
-#if TCL_UTF_MAX < 4
-static void ToUtf(const WCHAR *wSrc, char *dst);
-#else
-#define ToUtf(wSrc, dst) WideCharToMultiByte(CP_UTF8, 0, wSrc, -1, dst, MAX_PATH * TCL_UTF_MAX, NULL, NULL)
-#endif
/*
*---------------------------------------------------------------------------
@@ -163,7 +157,7 @@ TclpInitLibraryPath(
* installed DLL.
*/
- sprintf(installLib, "lib/tcl%s", TCL_VERSION);
+ snprintf(installLib, sizeof(installLib), "lib/tcl%s", TCL_VERSION);
/*
* Look for the library relative to the TCL_LIBRARY env variable. If the
@@ -250,12 +244,8 @@ AppendEnvironment(
* this is a unicode string.
*/
- if (GetEnvironmentVariableW(L"TCL_LIBRARY", wBuf, MAX_PATH) == 0) {
- buf[0] = '\0';
- GetEnvironmentVariableA("TCL_LIBRARY", buf, MAX_PATH);
- } else {
- ToUtf(wBuf, buf);
- }
+ GetEnvironmentVariableW(L"TCL_LIBRARY", wBuf, MAX_PATH);
+ WideCharToMultiByte(CP_UTF8, 0, wBuf, -1, buf, MAX_PATH * 3, NULL, NULL);
if (buf[0] != '\0') {
objPtr = Tcl_NewStringObj(buf, -1);
@@ -317,11 +307,8 @@ InitializeDefaultLibraryDir(
char name[(MAX_PATH + LIBRARY_SIZE) * 3];
char *end, *p;
- if (GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR)) == 0) {
- GetModuleFileNameA(hModule, name, sizeof(name));
- } else {
- ToUtf(wName, name);
- }
+ GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR));
+ WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, sizeof(name), NULL, NULL);
end = strrchr(name, '\\');
*end = '\0';
@@ -332,7 +319,7 @@ InitializeDefaultLibraryDir(
*end = '\\';
TclWinNoBackslash(name);
- sprintf(end + 1, "lib/tcl%s", TCL_VERSION);
+ snprintf(end + 1, LIBRARY_SIZE, "lib/tcl%s", TCL_VERSION);
*lengthPtr = strlen(name);
*valuePtr = (char *)ckalloc(*lengthPtr + 1);
*encodingPtr = NULL;
@@ -368,11 +355,8 @@ InitializeSourceLibraryDir(
char name[(MAX_PATH + LIBRARY_SIZE) * 3];
char *end, *p;
- if (GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR)) == 0) {
- GetModuleFileNameA(hModule, name, sizeof(name));
- } else {
- ToUtf(wName, name);
- }
+ GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR));
+ WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, sizeof(name), NULL, NULL);
end = strrchr(name, '\\');
*end = '\0';
@@ -383,7 +367,7 @@ InitializeSourceLibraryDir(
*end = '\\';
TclWinNoBackslash(name);
- sprintf(end + 1, "../library");
+ snprintf(end + 1, LIBRARY_SIZE, "../library");
*lengthPtr = strlen(name);
*valuePtr = (char *)ckalloc(*lengthPtr + 1);
*encodingPtr = NULL;
@@ -393,36 +377,6 @@ InitializeSourceLibraryDir(
/*
*---------------------------------------------------------------------------
*
- * ToUtf --
- *
- * Convert a wchar string to a UTF string.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-
-#if TCL_UTF_MAX < 4
-static void
-ToUtf(
- const WCHAR *wSrc,
- char *dst)
-{
- while (*wSrc != '\0') {
- dst += Tcl_UniCharToUtf(*wSrc, dst);
- wSrc++;
- }
- *dst = '\0';
-}
-#endif
-
-/*
- *---------------------------------------------------------------------------
- *
* TclpSetInitialEncodings --
*
* Based on the locale, determine the encoding of the operating system
@@ -471,7 +425,7 @@ Tcl_GetEncodingNameFromEnvironment(
Tcl_DStringAppend(bufPtr, "utf-8", 5);
} else {
Tcl_DStringSetLength(bufPtr, 2+TCL_INTEGER_SPACE);
- wsprintfA(Tcl_DStringValue(bufPtr), "cp%d", GetACP());
+ snprintf(Tcl_DStringValue(bufPtr), 2+TCL_INTEGER_SPACE, "cp%d", GetACP());
Tcl_DStringSetLength(bufPtr, strlen(Tcl_DStringValue(bufPtr)));
}
return Tcl_DStringValue(bufPtr);
@@ -555,7 +509,7 @@ TclpSetVariables(
if (osInfo.dwMajorVersion == 10 && osInfo.dwBuildNumber >= 22000) {
osInfo.dwMajorVersion = 11;
}
- wsprintfA(buffer, "%d.%d", osInfo.dwMajorVersion, osInfo.dwMinorVersion);
+ snprintf(buffer, sizeof(buffer), "%ld.%ld", osInfo.dwMajorVersion, osInfo.dwMinorVersion);
Tcl_SetVar2(interp, "tcl_platform", "osVersion", buffer, TCL_GLOBAL_ONLY);
if (sys.oemId.wProcessorArchitecture < NUMPROCESSORS) {
Tcl_SetVar2(interp, "tcl_platform", "machine",
diff --git a/win/tclWinInt.h b/win/tclWinInt.h
index 7aac7d0..b7974b8 100644
--- a/win/tclWinInt.h
+++ b/win/tclWinInt.h
@@ -79,8 +79,6 @@ MODULE_SCOPE void TclWinInit(HINSTANCE hInst);
MODULE_SCOPE TclFile TclWinMakeFile(HANDLE handle);
MODULE_SCOPE Tcl_Channel TclWinOpenConsoleChannel(HANDLE handle,
char *channelName, int permissions);
-MODULE_SCOPE Tcl_Channel TclWinOpenFileChannel(HANDLE handle, char *channelName,
- int permissions, int appendMode);
MODULE_SCOPE Tcl_Channel TclWinOpenSerialChannel(HANDLE handle,
char *channelName, int permissions);
MODULE_SCOPE HANDLE TclWinSerialOpen(HANDLE handle, const WCHAR *name,
diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c
index 00bc9fe..6c1331f 100644
--- a/win/tclWinPipe.c
+++ b/win/tclWinPipe.c
@@ -402,7 +402,7 @@ PipeCheckProc(
if (needEvent) {
infoPtr->flags |= PIPE_PENDING;
- evPtr = ckalloc(sizeof(PipeEvent));
+ evPtr = (PipeEvent *)ckalloc(sizeof(PipeEvent));
evPtr->header.proc = PipeEventProc;
evPtr->infoPtr = infoPtr;
Tcl_QueueEvent((Tcl_Event *) evPtr, TCL_QUEUE_TAIL);
@@ -433,7 +433,7 @@ TclWinMakeFile(
{
WinFile *filePtr;
- filePtr = ckalloc(sizeof(WinFile));
+ filePtr = (WinFile *)ckalloc(sizeof(WinFile));
filePtr->type = WIN_FILE;
filePtr->handle = handle;
@@ -1775,7 +1775,7 @@ TclpCreateCommandChannel(
Tcl_Pid *pidPtr) /* An array of process identifiers. */
{
char channelName[16 + TCL_INTEGER_SPACE];
- PipeInfo *infoPtr = ckalloc(sizeof(PipeInfo));
+ PipeInfo *infoPtr = (PipeInfo *)ckalloc(sizeof(PipeInfo));
PipeInit();
@@ -1834,7 +1834,7 @@ TclpCreateCommandChannel(
* unique, in case channels share handles (stdin/stdout).
*/
- sprintf(channelName, "file%" TCL_Z_MODIFIER "x", (size_t) infoPtr);
+ snprintf(channelName, sizeof(channelName), "file%" TCL_Z_MODIFIER "x", (size_t) infoPtr);
infoPtr->channel = Tcl_CreateChannel(&pipeChannelType, channelName,
infoPtr, infoPtr->validMask);
@@ -1929,7 +1929,7 @@ TclGetAndDetachPids(
return;
}
- pipePtr = Tcl_GetChannelInstanceData(chan);
+ pipePtr = (PipeInfo *)Tcl_GetChannelInstanceData(chan);
TclNewObj(pidsObj);
for (i = 0; i < pipePtr->numPids; i++) {
Tcl_ListObjAppendElement(NULL, pidsObj,
@@ -2315,7 +2315,7 @@ PipeOutputProc(
ckfree(infoPtr->writeBuf);
}
infoPtr->writeBufLen = toWrite;
- infoPtr->writeBuf = ckalloc(toWrite);
+ infoPtr->writeBuf = (char *)ckalloc(toWrite);
}
memcpy(infoPtr->writeBuf, buf, toWrite);
infoPtr->toWrite = toWrite;
@@ -2723,7 +2723,7 @@ TclWinAddProcess(
void *hProcess, /* Handle to process */
unsigned long id) /* Global process identifier */
{
- ProcInfo *procPtr = ckalloc(sizeof(ProcInfo));
+ ProcInfo *procPtr = (ProcInfo *)ckalloc(sizeof(ProcInfo));
PipeInit();
@@ -2823,7 +2823,7 @@ WaitForRead(
* or not. */
{
DWORD timeout, count;
- HANDLE *handle = ((WinFile *) infoPtr->readFile)->handle;
+ HANDLE handle = ((WinFile *) infoPtr->readFile)->handle;
while (1) {
/*
@@ -3243,7 +3243,7 @@ TclpOpenTemporaryFile(
do {
char number[TCL_INTEGER_SPACE + 4];
- sprintf(number, "%d.TMP", counter);
+ snprintf(number, sizeof(number), "%d.TMP", counter);
counter = (unsigned short) (counter + 1);
Tcl_WinUtfToTChar(number, strlen(number), &buf);
Tcl_DStringSetLength(&buf, Tcl_DStringLength(&buf) + 1);
@@ -3295,9 +3295,9 @@ TclPipeThreadCreateTI(
{
TclPipeThreadInfo *pipeTI;
#ifndef _PTI_USE_CKALLOC
- pipeTI = malloc(sizeof(TclPipeThreadInfo));
+ pipeTI = (TclPipeThreadInfo *)malloc(sizeof(TclPipeThreadInfo));
#else
- pipeTI = ckalloc(sizeof(TclPipeThreadInfo));
+ pipeTI = (TclPipeThreadInfo *)ckalloc(sizeof(TclPipeThreadInfo));
#endif /* !_PTI_USE_CKALLOC */
pipeTI->evControl = CreateEventW(NULL, FALSE, FALSE, NULL);
pipeTI->state = PTI_STATE_IDLE;
diff --git a/win/tclWinReg.c b/win/tclWinReg.c
index cd4ab33..87b33e1 100644
--- a/win/tclWinReg.c
+++ b/win/tclWinReg.c
@@ -1498,7 +1498,7 @@ AppendSystemError(
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (WCHAR *) tMsgPtrPtr,
0, NULL);
if (length == 0) {
- sprintf(msgBuf, "unknown error: %ld", error);
+ snprintf(msgBuf, sizeof(msgBuf), "unknown error: %ld", error);
msg = msgBuf;
} else {
char *msgPtr;
@@ -1524,7 +1524,7 @@ AppendSystemError(
msg = msgPtr;
}
- sprintf(id, "%ld", error);
+ snprintf(id, sizeof(id), "%ld", error);
Tcl_SetErrorCode(interp, "WINDOWS", id, msg, NULL);
Tcl_AppendToObj(resultPtr, msg, length);
Tcl_SetObjResult(interp, resultPtr);
diff --git a/win/tclWinSerial.c b/win/tclWinSerial.c
index d7fa9f5..53d2daf 100644
--- a/win/tclWinSerial.c
+++ b/win/tclWinSerial.c
@@ -524,7 +524,7 @@ SerialCheckProc(
if (needEvent) {
infoPtr->flags |= SERIAL_PENDING;
- evPtr = ckalloc(sizeof(SerialEvent));
+ evPtr = (SerialEvent *)ckalloc(sizeof(SerialEvent));
evPtr->header.proc = SerialEventProc;
evPtr->infoPtr = infoPtr;
Tcl_QueueEvent((Tcl_Event *) evPtr, TCL_QUEUE_TAIL);
@@ -1036,7 +1036,7 @@ SerialOutputProc(
ckfree(infoPtr->writeBuf);
}
infoPtr->writeBufLen = toWrite;
- infoPtr->writeBuf = ckalloc(toWrite);
+ infoPtr->writeBuf = (char *)ckalloc(toWrite);
}
memcpy(infoPtr->writeBuf, buf, toWrite);
infoPtr->toWrite = toWrite;
@@ -1435,7 +1435,7 @@ TclWinOpenSerialChannel(
SerialInit();
- infoPtr = ckalloc(sizeof(SerialInfo));
+ infoPtr = (SerialInfo *)ckalloc(sizeof(SerialInfo));
memset(infoPtr, 0, sizeof(SerialInfo));
infoPtr->validMask = permissions;
@@ -1456,7 +1456,7 @@ TclWinOpenSerialChannel(
* are shared between multiple channels (stdin/stdout).
*/
- sprintf(channelName, "file%" TCL_Z_MODIFIER "x", (size_t) infoPtr);
+ snprintf(channelName, 16 + TCL_INTEGER_SPACE, "file%" TCL_Z_MODIFIER "x", (size_t) infoPtr);
infoPtr->channel = Tcl_CreateChannel(&serialChannelType, channelName,
infoPtr, permissions);
@@ -1544,7 +1544,7 @@ SerialErrorStr(
if (error & ~((DWORD) (SERIAL_READ_ERRORS | SERIAL_WRITE_ERRORS))) {
char buf[TCL_INTEGER_SPACE + 1];
- wsprintfA(buf, "%d", error);
+ snprintf(buf, sizeof(buf), "%ld", error);
Tcl_DStringAppendElement(dsPtr, buf);
}
}
@@ -2041,7 +2041,7 @@ SerialGetOptionProc(
stop = (dcb.StopBits == ONESTOPBIT) ? "1" :
(dcb.StopBits == ONE5STOPBITS) ? "1.5" : "2";
- wsprintfA(buf, "%d,%c,%d,%s", dcb.BaudRate, parity,
+ snprintf(buf, sizeof(buf), "%ld,%c,%d,%s", dcb.BaudRate, parity,
dcb.ByteSize, stop);
Tcl_DStringAppendElement(dsPtr, buf);
}
@@ -2057,7 +2057,7 @@ SerialGetOptionProc(
char buf[TCL_INTEGER_SPACE + 1];
valid = 1;
- wsprintfA(buf, "%d", infoPtr->blockTime);
+ snprintf(buf, sizeof(buf), "%d", infoPtr->blockTime);
Tcl_DStringAppendElement(dsPtr, buf);
}
@@ -2073,9 +2073,9 @@ SerialGetOptionProc(
char buf[TCL_INTEGER_SPACE + 1];
valid = 1;
- wsprintfA(buf, "%d", infoPtr->sysBufRead);
+ snprintf(buf, sizeof(buf), "%ld", infoPtr->sysBufRead);
Tcl_DStringAppendElement(dsPtr, buf);
- wsprintfA(buf, "%d", infoPtr->sysBufWrite);
+ snprintf(buf, sizeof(buf), "%ld", infoPtr->sysBufWrite);
Tcl_DStringAppendElement(dsPtr, buf);
}
if (len == 0) {
@@ -2102,9 +2102,10 @@ SerialGetOptionProc(
}
return TCL_ERROR;
}
- sprintf(buf, "%c", dcb.XonChar);
+ buf[1] = '\0';
+ buf[0] = dcb.XonChar;
Tcl_DStringAppendElement(dsPtr, buf);
- sprintf(buf, "%c", dcb.XoffChar);
+ buf[0] = dcb.XoffChar;
Tcl_DStringAppendElement(dsPtr, buf);
}
if (len == 0) {
@@ -2156,9 +2157,9 @@ SerialGetOptionProc(
count = (int) cStat.cbOutQue + infoPtr->writeQueue;
LeaveCriticalSection(&infoPtr->csWrite);
- wsprintfA(buf, "%d", inBuffered + cStat.cbInQue);
+ snprintf(buf, sizeof(buf), "%ld", inBuffered + cStat.cbInQue);
Tcl_DStringAppendElement(dsPtr, buf);
- wsprintfA(buf, "%d", outBuffered + count);
+ snprintf(buf, sizeof(buf), "%d", outBuffered + count);
Tcl_DStringAppendElement(dsPtr, buf);
}
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index 09b5d52..1c13479 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -2072,7 +2072,7 @@ Tcl_OpenTcpClient(
return NULL;
}
- sprintf(channelName, SOCK_TEMPLATE, statePtr);
+ snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, statePtr);
statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName,
statePtr, (TCL_READABLE | TCL_WRITABLE));
@@ -2133,7 +2133,7 @@ Tcl_MakeTcpClientChannel(
statePtr->selectEvents = FD_READ | FD_CLOSE | FD_WRITE;
SendSelectMessage(tsdPtr, SELECT, statePtr);
- sprintf(channelName, SOCK_TEMPLATE, statePtr);
+ snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, statePtr);
statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName,
statePtr, (TCL_READABLE | TCL_WRITABLE));
Tcl_SetChannelOption(NULL, statePtr->channel, "-translation", "auto crlf");
@@ -2296,7 +2296,7 @@ Tcl_OpenTcpServer(
statePtr->acceptProc = acceptProc;
statePtr->acceptProcData = acceptProcData;
- sprintf(channelName, SOCK_TEMPLATE, statePtr);
+ snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, statePtr);
statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName,
statePtr, 0);
/*
@@ -2381,7 +2381,7 @@ TcpAccept(
newInfoPtr->selectEvents = (FD_READ | FD_WRITE | FD_CLOSE);
SendSelectMessage(tsdPtr, SELECT, newInfoPtr);
- sprintf(channelName, SOCK_TEMPLATE, newInfoPtr);
+ snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, newInfoPtr);
newInfoPtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName,
newInfoPtr, (TCL_READABLE | TCL_WRITABLE));
if (Tcl_SetChannelOption(NULL, newInfoPtr->channel, "-translation",
diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c
index 44b5f6c..65c4b3c 100644
--- a/win/tclWinThrd.c
+++ b/win/tclWinThrd.c
@@ -574,7 +574,7 @@ Tcl_MutexLock(
*/
if (*mutexPtr == NULL) {
- csPtr = ckalloc(sizeof(CRITICAL_SECTION));
+ csPtr = (CRITICAL_SECTION *)ckalloc(sizeof(CRITICAL_SECTION));
InitializeCriticalSection(csPtr);
*mutexPtr = (Tcl_Mutex)csPtr;
TclRememberMutex(mutexPtr);
@@ -717,7 +717,7 @@ Tcl_ConditionWait(
*/
if (*condPtr == NULL) {
- winCondPtr = ckalloc(sizeof(WinCondition));
+ winCondPtr = (WinCondition *)ckalloc(sizeof(WinCondition));
InitializeCriticalSection(&winCondPtr->condLock);
winCondPtr->firstPtr = NULL;
winCondPtr->lastPtr = NULL;
@@ -946,7 +946,7 @@ TclpNewAllocMutex(void)
{
struct allocMutex *lockPtr;
- lockPtr = malloc(sizeof(struct allocMutex));
+ lockPtr = (struct allocMutex *)malloc(sizeof(struct allocMutex));
if (lockPtr == NULL) {
Tcl_Panic("could not allocate lock");
}
@@ -1045,7 +1045,7 @@ TclpThreadCreateKey(void)
{
DWORD *key;
- key = TclpSysAlloc(sizeof *key, 0);
+ key = (DWORD *)TclpSysAlloc(sizeof *key, 0);
if (key == NULL) {
Tcl_Panic("unable to allocate thread key!");
}
@@ -1063,7 +1063,7 @@ void
TclpThreadDeleteKey(
void *keyPtr)
{
- DWORD *key = keyPtr;
+ DWORD *key = (DWORD *)keyPtr;
if (!TlsFree(*key)) {
Tcl_Panic("unable to delete key");
@@ -1077,7 +1077,7 @@ TclpThreadSetGlobalTSD(
void *tsdKeyPtr,
void *ptr)
{
- DWORD *key = tsdKeyPtr;
+ DWORD *key = (DWORD *)tsdKeyPtr;
if (!TlsSetValue(*key, ptr)) {
Tcl_Panic("unable to set global TSD value");
@@ -1088,7 +1088,7 @@ void *
TclpThreadGetGlobalTSD(
void *tsdKeyPtr)
{
- DWORD *key = tsdKeyPtr;
+ DWORD *key = (DWORD *)tsdKeyPtr;
return TlsGetValue(*key);
}