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 /win/tclWinSerial.c | |
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 'win/tclWinSerial.c')
-rw-r--r-- | win/tclWinSerial.c | 27 |
1 files changed, 14 insertions, 13 deletions
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); } |