summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixScale.c
diff options
context:
space:
mode:
authorfvogel <fvogel@noemail.net>2017-10-07 20:08:57 (GMT)
committerfvogel <fvogel@noemail.net>2017-10-07 20:08:57 (GMT)
commitde84c6e3909b8f7f9b467ecd24c46a934122c273 (patch)
treee80c49cb31592eebf8c5674684666cbd067c5e3f /unix/tkUnixScale.c
parent70fb6287ec3f67da0ce3a6782d35ef56475ceaae (diff)
downloadtk-de84c6e3909b8f7f9b467ecd24c46a934122c273.zip
tk-de84c6e3909b8f7f9b467ecd24c46a934122c273.tar.gz
tk-de84c6e3909b8f7f9b467ecd24c46a934122c273.tar.bz2
Fix more issues with sprintf in the scale widget.
FossilOrigin-Name: 9c78924bf36d165a00073fb0f99391d17c25e39facd0655fa59fb9863ca5f47a
Diffstat (limited to 'unix/tkUnixScale.c')
-rw-r--r--unix/tkUnixScale.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/unix/tkUnixScale.c b/unix/tkUnixScale.c
index c348037..8f88018 100644
--- a/unix/tkUnixScale.c
+++ b/unix/tkUnixScale.c
@@ -13,6 +13,10 @@
#include "tkInt.h"
#include "tkScale.h"
+#if defined(_WIN32)
+#define snprintf _snprintf
+#endif
+
/*
* Forward declarations for functions defined later in this file:
*/
@@ -267,7 +271,9 @@ DisplayVerticalValue(
Tk_GetFontMetrics(scalePtr->tkfont, &fm);
y = TkScaleValueToPixel(scalePtr, value) + fm.ascent/2;
- sprintf(valueString, scalePtr->format, value);
+ if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format, value) < 0) {
+ valueString[TCL_DOUBLE_SPACE - 1] = '\0';
+ }
length = (int) strlen(valueString);
width = Tk_TextWidth(scalePtr->tkfont, valueString, length);
@@ -352,7 +358,10 @@ DisplayHorizontalScale(
ticks = fabs((scalePtr->toValue - scalePtr->fromValue)
/ tickInterval);
- sprintf(valueString, scalePtr->format, scalePtr->fromValue);
+ if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format,
+ scalePtr->fromValue) < 0) {
+ valueString[TCL_DOUBLE_SPACE - 1] = '\0';
+ }
maxTicks = (double) Tk_Width(tkwin)
/ (double) Tk_TextWidth(scalePtr->tkfont, valueString, -1);
if (ticks > maxTicks) {
@@ -484,7 +493,9 @@ DisplayHorizontalValue(
x = TkScaleValueToPixel(scalePtr, value);
Tk_GetFontMetrics(scalePtr->tkfont, &fm);
y = top + fm.ascent;
- sprintf(valueString, scalePtr->format, value);
+ if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format, value) < 0) {
+ valueString[TCL_DOUBLE_SPACE - 1] = '\0';
+ }
length = (int) strlen(valueString);
width = Tk_TextWidth(scalePtr->tkfont, valueString, length);
@@ -551,7 +562,10 @@ TkpDisplayScale(
Tcl_Preserve(scalePtr);
if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) {
Tcl_Preserve(interp);
- sprintf(string, scalePtr->format, scalePtr->value);
+ if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format,
+ scalePtr->value) < 0) {
+ string[TCL_DOUBLE_SPACE - 1] = '\0';
+ }
Tcl_DStringInit(&buf);
Tcl_DStringAppend(&buf, scalePtr->command, -1);
Tcl_DStringAppend(&buf, " ", -1);