diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-03-30 15:19:44 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-03-30 15:19:44 (GMT) |
commit | 191fecdc87592dfea94718bc716551c72f072c33 (patch) | |
tree | 4aa12b60fc6ad7ca4c19658d774dee4326ad165b /unix | |
parent | 784535a35c779f46886fe9a880b706c979efdd77 (diff) | |
download | tcl-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 'unix')
-rw-r--r-- | unix/dltest/pkgb.c | 5 | ||||
-rw-r--r-- | unix/tclUnixChan.c | 12 | ||||
-rw-r--r-- | unix/tclUnixInit.c | 4 | ||||
-rw-r--r-- | unix/tclUnixPipe.c | 6 | ||||
-rw-r--r-- | unix/tclUnixSock.c | 8 | ||||
-rw-r--r-- | unix/tclUnixTest.c | 2 | ||||
-rw-r--r-- | unix/tclUnixThrd.c | 2 |
7 files changed, 21 insertions, 18 deletions
diff --git a/unix/dltest/pkgb.c b/unix/dltest/pkgb.c index 8d8d123..e66c9ec 100644 --- a/unix/dltest/pkgb.c +++ b/unix/dltest/pkgb.c @@ -13,6 +13,9 @@ #undef STATIC_BUILD #include "tcl.h" +#if defined(_WIN32) && defined(_MSC_VER) +# define snprintf _snprintf +#endif /* * Prototypes for procedures defined later in this file: @@ -63,7 +66,7 @@ Pkgb_SubObjCmd( if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK) || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) { char buf[TCL_INTEGER_SPACE]; - sprintf(buf, "%d", Tcl_GetErrorLine(interp)); + snprintf(buf, sizeof(buf), "%d", Tcl_GetErrorLine(interp)); Tcl_AppendResult(interp, " in line: ", buf, NULL); return TCL_ERROR; } diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index b49dde7..9330207 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -838,7 +838,7 @@ TtyGetOptionProc( valid = 1; TtyGetAttributes(fsPtr->fd, &tty); - sprintf(buf, "%d,%c,%d,%d", tty.baud, tty.parity, tty.data, tty.stop); + snprintf(buf, sizeof(buf), "%d,%c,%d,%d", tty.baud, tty.parity, tty.data, tty.stop); Tcl_DStringAppendElement(dsPtr, buf); } @@ -885,9 +885,9 @@ TtyGetOptionProc( inBuffered = Tcl_InputBuffered(fsPtr->channel); outBuffered = Tcl_OutputBuffered(fsPtr->channel); - sprintf(buf, "%d", inBuffered+inQueue); + snprintf(buf, sizeof(buf), "%d", inBuffered+inQueue); Tcl_DStringAppendElement(dsPtr, buf); - sprintf(buf, "%d", outBuffered+outQueue); + snprintf(buf, sizeof(buf), "%d", outBuffered+outQueue); Tcl_DStringAppendElement(dsPtr, buf); } @@ -1439,7 +1439,7 @@ TclpOpenFileChannel( fcntl(fd, F_SETFD, FD_CLOEXEC); - sprintf(channelName, "file%d", fd); + snprintf(channelName, sizeof(channelName), "file%d", fd); #ifdef SUPPORTS_TTY if (strcmp(native, "/dev/tty") != 0 && isatty(fd)) { @@ -1531,7 +1531,7 @@ Tcl_MakeFileChannel( #ifdef SUPPORTS_TTY if (isatty(fd)) { channelTypePtr = &ttyChannelType; - sprintf(channelName, "serial%d", fd); + snprintf(channelName, sizeof(channelName), "serial%d", fd); } else #endif /* SUPPORTS_TTY */ if ((getsockname(fd, (struct sockaddr *)&sockaddr, &sockaddrLen) == 0) @@ -1540,7 +1540,7 @@ Tcl_MakeFileChannel( return TclpMakeTcpClientChannelMode(INT2PTR(fd), mode); } else { channelTypePtr = &fileChannelType; - sprintf(channelName, "file%d", fd); + snprintf(channelName, sizeof(channelName), "file%d", fd); } fsPtr = ckalloc(sizeof(FileState)); diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index 47b8df3..2aae158 100644 --- a/unix/tclUnixInit.c +++ b/unix/tclUnixInit.c @@ -500,7 +500,7 @@ TclpInitLibraryPath( * installed. */ - sprintf(installLib, "lib/tcl%s", TCL_VERSION); + snprintf(installLib, sizeof(installLib), "lib/tcl%s", TCL_VERSION); /* * If TCL_LIBRARY is set, search there. @@ -899,7 +899,7 @@ TclpSetVariables( osInfo.dwMajorVersion = 11; } Tcl_SetVar2(interp, "tcl_platform", "os", "Windows NT", TCL_GLOBAL_ONLY); - sprintf(buffer, "%d.%d", osInfo.dwMajorVersion, osInfo.dwMinorVersion); + snprintf(buffer, sizeof(buffer), "%d.%d", osInfo.dwMajorVersion, osInfo.dwMinorVersion); Tcl_SetVar2(interp, "tcl_platform", "osVersion", buffer, TCL_GLOBAL_ONLY); if (sysInfo.wProcessorArchitecture < NUMPROCESSORS) { Tcl_SetVar2(interp, "tcl_platform", "machine", diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index d5cb765..9d27632 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -475,7 +475,7 @@ TclpCreateProcess( || (!joinThisError && !SetupStdFile(errorFile, TCL_STDERR)) || (joinThisError && ((dup2(1,2) == -1) || (fcntl(2, F_SETFD, 0) != 0)))) { - sprintf(errSpace, + snprintf(errSpace, sizeof(errSpace), "%dforked process couldn't set up input/output", errno); len = strlen(errSpace); if (len != (size_t) write(fd, errSpace, len)) { @@ -490,7 +490,7 @@ TclpCreateProcess( RestoreSignals(); execvp(newArgv[0], newArgv); /* INTL: Native. */ - sprintf(errSpace, "%dcouldn't execute \"%.150s\"", errno, argv[0]); + snprintf(errSpace, sizeof(errSpace), "%dcouldn't execute \"%.150s\"", errno, argv[0]); len = strlen(errSpace); if (len != (size_t) write(fd, errSpace, len)) { Tcl_Panic("TclpCreateProcess: unable to write to errPipeOut"); @@ -782,7 +782,7 @@ TclpCreateCommandChannel( * natural to use "pipe%d". */ - sprintf(channelName, "file%d", channelId); + snprintf(channelName, sizeof(channelName), "file%d", channelId); statePtr->channel = Tcl_CreateChannel(&pipeChannelType, channelName, statePtr, mode); return statePtr->channel; diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index ffb70e1..3c56a5e 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -1428,7 +1428,7 @@ Tcl_OpenTcpClient( return NULL; } - sprintf(channelName, SOCK_TEMPLATE, (long)statePtr); + snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, (long)statePtr); statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, statePtr, TCL_READABLE | TCL_WRITABLE); @@ -1495,7 +1495,7 @@ TclpMakeTcpClientChannelMode( statePtr->fds.fd = PTR2INT(sock); statePtr->flags = 0; - sprintf(channelName, SOCK_TEMPLATE, (long)statePtr); + snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, (long)statePtr); statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, statePtr, mode); @@ -1654,7 +1654,7 @@ Tcl_OpenTcpServer( memset(statePtr, 0, sizeof(TcpState)); statePtr->acceptProc = acceptProc; statePtr->acceptProcData = acceptProcData; - sprintf(channelName, SOCK_TEMPLATE, (long) statePtr); + snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, (long) statePtr); newfds = &statePtr->fds; } else { newfds = (TcpFdList *)ckalloc(sizeof(TcpFdList)); @@ -1747,7 +1747,7 @@ TcpAccept( newSockState->flags = 0; newSockState->fds.fd = newsock; - sprintf(channelName, SOCK_TEMPLATE, (long)newSockState); + snprintf(channelName, sizeof(channelName), SOCK_TEMPLATE, (long)newSockState); newSockState->channel = Tcl_CreateChannel(&tcpChannelType, channelName, newSockState, TCL_READABLE | TCL_WRITABLE); diff --git a/unix/tclUnixTest.c b/unix/tclUnixTest.c index c5ac52a..9b89b2f 100644 --- a/unix/tclUnixTest.c +++ b/unix/tclUnixTest.c @@ -202,7 +202,7 @@ TestfilehandlerCmd( argv[0], " counts index\"", NULL); return TCL_ERROR; } - sprintf(buf, "%d %d", pipePtr->readCount, pipePtr->writeCount); + snprintf(buf, sizeof(buf), "%d %d", pipePtr->readCount, pipePtr->writeCount); Tcl_AppendResult(interp, buf, NULL); } else if (strcmp(argv[1], "create") == 0) { if (argc != 5) { diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index afb795d..e4a3c68 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -667,7 +667,7 @@ TclpInetNtoa( ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); unsigned char *b = (unsigned char*) &addr.s_addr; - sprintf(tsdPtr->nabuf, "%u.%u.%u.%u", b[0], b[1], b[2], b[3]); + snprintf(tsdPtr->nabuf, sizeof(tsdPtr->nabuf), "%u.%u.%u.%u", b[0], b[1], b[2], b[3]); return tsdPtr->nabuf; #else return inet_ntoa(addr); |