diff options
author | fvogel <fvogelnew1@free.fr> | 2023-01-12 00:04:55 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2023-01-12 00:04:55 (GMT) |
commit | 91c03f8f7b13c7f0c997749c6808cd01db9807a3 (patch) | |
tree | f9ffd1e4bcab63d71c9d4ba131d867cbeca55db2 | |
parent | 12c0146aaec25379a108581c8582dd79eedcc066 (diff) | |
download | tk-91c03f8f7b13c7f0c997749c6808cd01db9807a3.zip tk-91c03f8f7b13c7f0c997749c6808cd01db9807a3.tar.gz tk-91c03f8f7b13c7f0c997749c6808cd01db9807a3.tar.bz2 |
Provide explicit size in snprintf when needed. Fix gcc warning: 'argument to ‘sizeof’ in ‘snprintf’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]'
-rw-r--r-- | generic/tkBusy.c | 2 | ||||
-rw-r--r-- | generic/tkCanvLine.c | 2 | ||||
-rw-r--r-- | generic/tkCanvUtil.c | 4 | ||||
-rw-r--r-- | generic/tkConfig.c | 8 | ||||
-rw-r--r-- | generic/tkEntry.c | 7 | ||||
-rw-r--r-- | generic/tkOldConfig.c | 4 | ||||
-rw-r--r-- | generic/tkSelect.c | 2 | ||||
-rw-r--r-- | generic/tkStubInit.c | 2 | ||||
-rw-r--r-- | generic/tkText.c | 2 | ||||
-rw-r--r-- | generic/tkTextIndex.c | 2 | ||||
-rw-r--r-- | generic/tkUtil.c | 4 | ||||
-rw-r--r-- | macosx/tkMacOSXPort.h | 2 | ||||
-rw-r--r-- | unix/tkUnixPort.h | 2 | ||||
-rw-r--r-- | unix/tkUnixSend.c | 2 |
14 files changed, 23 insertions, 22 deletions
diff --git a/generic/tkBusy.c b/generic/tkBusy.c index ea3ac16..075b892 100644 --- a/generic/tkBusy.c +++ b/generic/tkBusy.c @@ -558,7 +558,7 @@ CreateBusy( tkChild = NextChild(tkChild)) { Tk_MakeWindowExist(tkChild); } - snprintf(name, sizeof(name), fmt, Tk_Name(tkRef)); + snprintf(name, length + 6, fmt, Tk_Name(tkRef)); tkBusy = Tk_CreateWindow(interp, tkParent, name, NULL); ckfree(name); diff --git a/generic/tkCanvLine.c b/generic/tkCanvLine.c index cfa55f5..642d1c2 100644 --- a/generic/tkCanvLine.c +++ b/generic/tkCanvLine.c @@ -2083,7 +2083,7 @@ PrintArrowShape( LineItem *linePtr = (LineItem *) recordPtr; char *buffer = (char *)ckalloc(120); - snprintf(buffer, sizeof(buffer), "%.5g %.5g %.5g", linePtr->arrowShapeA, + snprintf(buffer, 120, "%.5g %.5g %.5g", linePtr->arrowShapeA, linePtr->arrowShapeB, linePtr->arrowShapeC); *freeProcPtr = TCL_DYNAMIC; return buffer; diff --git a/generic/tkCanvUtil.c b/generic/tkCanvUtil.c index 9eedf6b..5e586ab 100644 --- a/generic/tkCanvUtil.c +++ b/generic/tkCanvUtil.c @@ -578,9 +578,9 @@ TkCanvasDashPrintProc( *freeProcPtr = TCL_DYNAMIC; p = (i > (int)sizeof(char *)) ? dash->pattern.pt : dash->pattern.array; - snprintf(buffer, sizeof(buffer), "%d", *p++ & 0xff); + snprintf(buffer, 4 * i, "%d", *p++ & 0xff); while (--i) { - snprintf(buffer+strlen(buffer), sizeof(buffer)-strlen(buffer), " %d", *p++ & 0xff); + snprintf(buffer + strlen(buffer), 4 * i - strlen(buffer), " %d", *p++ & 0xff); } return buffer; } diff --git a/generic/tkConfig.c b/generic/tkConfig.c index 69f0fa6..1ff5c65 100644 --- a/generic/tkConfig.c +++ b/generic/tkConfig.c @@ -517,19 +517,19 @@ Tk_InitOptions( switch (source) { case OPTION_DATABASE: - snprintf(msg, sizeof(msg), "\n (database entry for \"%.50s\")", + snprintf(msg, 200, "\n (database entry for \"%.50s\")", optionPtr->specPtr->optionName); break; case SYSTEM_DEFAULT: - snprintf(msg, sizeof(msg), "\n (system default for \"%.50s\")", + snprintf(msg, 200, "\n (system default for \"%.50s\")", optionPtr->specPtr->optionName); break; case TABLE_DEFAULT: - snprintf(msg, sizeof(msg), "\n (default value for \"%.50s\")", + snprintf(msg, 200, "\n (default value for \"%.50s\")", optionPtr->specPtr->optionName); } if (tkwin != NULL) { - snprintf(msg + strlen(msg) - 1, sizeof(msg) - (strlen(msg) - 1), " in widget \"%.50s\")", + snprintf(msg + strlen(msg) - 1, 200 - (strlen(msg) - 1), " in widget \"%.50s\")", Tk_PathName(tkwin)); } Tcl_AddErrorInfo(interp, msg); diff --git a/generic/tkEntry.c b/generic/tkEntry.c index c0388a3..fc574a0 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -1113,6 +1113,7 @@ ConfigureEntry( double oldFrom = 0.0; /* lint initialization */ double oldTo = 0.0; /* lint initialization */ int code; + size_t formatSpace = TCL_DOUBLE_SPACE; /* * Eliminate any existing trace on a variable monitored by the entry. @@ -1201,7 +1202,7 @@ ConfigureEntry( */ int min, max; - size_t formatLen, formatSpace = TCL_DOUBLE_SPACE; + size_t formatLen; char fbuf[4], *fmt = sbPtr->reqFormat; formatLen = strlen(fmt); @@ -1378,7 +1379,7 @@ ConfigureEntry( } else if (dvalue < sbPtr->fromValue) { dvalue = sbPtr->fromValue; } - snprintf(sbPtr->formatBuf, sizeof(sbPtr->formatBuf), sbPtr->valueFormat, dvalue); + snprintf(sbPtr->formatBuf, formatSpace, sbPtr->valueFormat, dvalue); /* * No check for error return here as well, because any possible @@ -4408,7 +4409,7 @@ SpinboxInvoke( dvalue = sbPtr->toValue; } } - snprintf(sbPtr->formatBuf, sizeof(sbPtr->formatBuf), sbPtr->valueFormat, dvalue); + snprintf(sbPtr->formatBuf, TCL_DOUBLE_SPACE, sbPtr->valueFormat, dvalue); code = EntryValueChanged(entryPtr, sbPtr->formatBuf); } } diff --git a/generic/tkOldConfig.c b/generic/tkOldConfig.c index 7711e2b..5d8a042 100644 --- a/generic/tkOldConfig.c +++ b/generic/tkOldConfig.c @@ -781,7 +781,7 @@ FormatConfigValue( } break; case TK_CONFIG_INT: - snprintf(buffer, sizeof(buffer), "%d", *((int *)ptr)); + snprintf(buffer, 200, "%d", *((int *)ptr)); result = buffer; break; case TK_CONFIG_DOUBLE: @@ -859,7 +859,7 @@ FormatConfigValue( result = Tk_NameOfJoinStyle(*((int *)ptr)); break; case TK_CONFIG_PIXELS: - snprintf(buffer, sizeof(buffer),"%d", *((int *)ptr)); + snprintf(buffer, 200, "%d", *((int *)ptr)); result = buffer; break; case TK_CONFIG_MM: diff --git a/generic/tkSelect.c b/generic/tkSelect.c index fae72c6..4a84e57 100644 --- a/generic/tkSelect.c +++ b/generic/tkSelect.c @@ -1484,7 +1484,7 @@ TkSelDefaultSelection( if (maxBytes < 20) { return -1; } - snprintf(buffer, sizeof(buffer), "0x%x", (unsigned int) infoPtr->time); + snprintf(buffer, maxBytes, "0x%x", (unsigned int) infoPtr->time); *typePtr = XA_INTEGER; return strlen(buffer); } diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c index 23397db..47742c1 100644 --- a/generic/tkStubInit.c +++ b/generic/tkStubInit.c @@ -151,7 +151,7 @@ TkpPrintWindowId( * the hex representation of a pointer. */ Window window) /* Window to be printed into buffer. */ { - snprintf(buf, sizeof(buf), "0x%" TCL_Z_MODIFIER "x", (size_t)window); + snprintf(buf, TCL_INTEGER_SPACE, "0x%" TCL_Z_MODIFIER "x", (size_t)window); } int diff --git a/generic/tkText.c b/generic/tkText.c index ea6c5fc..ce9bce7 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -6836,7 +6836,7 @@ TkpTesttextCmd( size_t len; int lineIndex, byteIndex, byteOffset; TkTextIndex index; - char buf[64]; + char buf[TK_POS_CHARS]; Tcl_CmdInfo info; if (objc < 3) { diff --git a/generic/tkTextIndex.c b/generic/tkTextIndex.c index 7417e7f..c371530 100644 --- a/generic/tkTextIndex.c +++ b/generic/tkTextIndex.c @@ -1136,7 +1136,7 @@ TkTextPrintIndex( charIndex += numBytes; } - return snprintf(string, sizeof(string), "%d.%d", + return snprintf(string, TK_POS_CHARS, "%d.%d", TkBTreeLinesTo(textPtr, indexPtr->linePtr) + 1, charIndex); } diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 63bbc0e..73a323b 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -431,7 +431,7 @@ TkOffsetPrintProc( return "end"; } p = (char *)ckalloc(32); - snprintf(p, sizeof(p), "%d", offsetPtr->flags & ~TK_OFFSET_INDEX); + snprintf(p, 32, "%d", offsetPtr->flags & ~TK_OFFSET_INDEX); *freeProcPtr = TCL_DYNAMIC; return p; } @@ -464,7 +464,7 @@ TkOffsetPrintProc( if (offsetPtr->flags & TK_OFFSET_RELATIVE) { *q++ = '#'; } - snprintf(q, sizeof(q), "%d,%d", offsetPtr->xoffset, offsetPtr->yoffset); + snprintf(q, 32, "%d,%d", offsetPtr->xoffset, offsetPtr->yoffset); *freeProcPtr = TCL_DYNAMIC; return p; } diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h index b5aa459..2a50663 100644 --- a/macosx/tkMacOSXPort.h +++ b/macosx/tkMacOSXPort.h @@ -162,7 +162,7 @@ */ #define TkpPrintWindowId(buf,w) \ - snprintf((buf), sizeof(buf), "0x%lx", (unsigned long) (w)) + snprintf((buf), TCL_INTEGER_SPACE, "0x%lx", (unsigned long) (w)) /* * Turn off Tk double-buffering as Aqua windows are already double-buffered. diff --git a/unix/tkUnixPort.h b/unix/tkUnixPort.h index 7f764a4..8b6efce 100644 --- a/unix/tkUnixPort.h +++ b/unix/tkUnixPort.h @@ -191,7 +191,7 @@ #ifndef __CYGWIN__ #define TkpPrintWindowId(buf,w) \ - snprintf((buf), sizeof(buf), "0x%08lx", (unsigned long) (w)) + snprintf((buf), TCL_INTEGER_SPACE, "0x%08lx", (unsigned long) (w)) #endif #endif /* _UNIXPORT */ diff --git a/unix/tkUnixSend.c b/unix/tkUnixSend.c index 523f178..bd33576 100644 --- a/unix/tkUnixSend.c +++ b/unix/tkUnixSend.c @@ -1796,7 +1796,7 @@ AppendErrorProc( pcPtr = pcPtr->nextPtr) { if ((pcPtr == pendingPtr) && (pcPtr->result == NULL)) { pcPtr->result = (char *)ckalloc(strlen(pcPtr->target) + 50); - snprintf(pcPtr->result, sizeof(pcPtr->result), "no application named \"%s\"", + snprintf(pcPtr->result, strlen(pcPtr->target) + 50, "no application named \"%s\"", pcPtr->target); pcPtr->code = TCL_ERROR; pcPtr->gotResponse = 1; |