summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-10-30 15:16:37 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-10-30 15:16:37 (GMT)
commit277e4c03ced86ddf627807595297854fac523c9a (patch)
tree96d54249d6fe3ce0e844f00f245ec68bd1bc653a
parent90f1bb2871f27fb60b636b4b70b9b6e5f9dc3eda (diff)
parent69a9c784d764e95b1b34c1b37d7a7df4a4c90647 (diff)
downloadtk-277e4c03ced86ddf627807595297854fac523c9a.zip
tk-277e4c03ced86ddf627807595297854fac523c9a.tar.gz
tk-277e4c03ced86ddf627807595297854fac523c9a.tar.bz2
[3417012] Stop [scale] segfault when -digits too big.
-rw-r--r--generic/tkScale.c7
-rw-r--r--generic/tkScale.h6
-rw-r--r--macosx/tkMacOSXScale.c2
-rw-r--r--tests/scale.test5
-rw-r--r--unix/tkUnixScale.c8
5 files changed, 15 insertions, 13 deletions
diff --git a/generic/tkScale.c b/generic/tkScale.c
index 28e5b16..69a7d91 100644
--- a/generic/tkScale.c
+++ b/generic/tkScale.c
@@ -808,6 +808,9 @@ ComputeFormat(
*/
numDigits = scalePtr->digits;
+ if (numDigits > TCL_MAX_PREC) {
+ numDigits = 0;
+ }
if (numDigits <= 0) {
if (scalePtr->resolution > 0) {
/*
@@ -888,7 +891,7 @@ static void
ComputeScaleGeometry(
register TkScale *scalePtr) /* Information about widget. */
{
- char valueString[PRINT_CHARS];
+ char valueString[TCL_DOUBLE_SPACE];
int tmp, valuePixels, x, y, extraSpace;
Tk_FontMetrics fm;
@@ -1304,7 +1307,7 @@ ScaleSetVariable(
register TkScale *scalePtr) /* Info about widget. */
{
if (scalePtr->varNamePtr != NULL) {
- char string[PRINT_CHARS];
+ char string[TCL_DOUBLE_SPACE];
sprintf(string, scalePtr->format, scalePtr->value);
scalePtr->flags |= SETTING_VAR;
diff --git a/generic/tkScale.h b/generic/tkScale.h
index f406bf6..a2c5f2b 100644
--- a/generic/tkScale.h
+++ b/generic/tkScale.h
@@ -220,12 +220,6 @@ typedef struct TkScale {
#define SPACING 2
/*
- * How many characters of space to provide when formatting the scale's value:
- */
-
-#define PRINT_CHARS 150
-
-/*
* Declaration of procedures used in the implementation of the scale widget.
*/
diff --git a/macosx/tkMacOSXScale.c b/macosx/tkMacOSXScale.c
index e94763d..a37029c 100644
--- a/macosx/tkMacOSXScale.c
+++ b/macosx/tkMacOSXScale.c
@@ -145,7 +145,7 @@ TkpDisplayScale(
Tk_Window tkwin = scalePtr->tkwin;
Tcl_Interp *interp = scalePtr->interp;
int result;
- char string[PRINT_CHARS];
+ char string[TCL_DOUBLE_SPACE];
MacScale *macScalePtr = (MacScale *) clientData;
Rect r;
WindowRef windowRef;
diff --git a/tests/scale.test b/tests/scale.test
index 657f668..d7ded7f 100644
--- a/tests/scale.test
+++ b/tests/scale.test
@@ -387,6 +387,11 @@ test scale-6.20 {ComputeFormat procedure} {
.s set 1001.23456789
.s get
} {1001.235}
+test scale-6.21 {ComputeFormat procedure} {
+ .s configure -length 200 -from 1000 -to 1001.8 -resolution 0 -digits 200
+ .s set 1001.23456789
+ .s get
+} {1001.235}
test scale-7.1 {ComputeScaleGeometry procedure} {nonPortable fonts} {
catch {destroy .s}
diff --git a/unix/tkUnixScale.c b/unix/tkUnixScale.c
index e158549..71f9ea8 100644
--- a/unix/tkUnixScale.c
+++ b/unix/tkUnixScale.c
@@ -262,7 +262,7 @@ DisplayVerticalValue(
{
register Tk_Window tkwin = scalePtr->tkwin;
int y, width, length;
- char valueString[PRINT_CHARS];
+ char valueString[TCL_DOUBLE_SPACE];
Tk_FontMetrics fm;
Tk_GetFontMetrics(scalePtr->tkfont, &fm);
@@ -341,7 +341,7 @@ DisplayHorizontalScale(
*/
if (tickInterval != 0) {
- char valueString[PRINT_CHARS];
+ char valueString[TCL_DOUBLE_SPACE];
double ticks, maxTicks;
/*
@@ -478,7 +478,7 @@ DisplayHorizontalValue(
{
register Tk_Window tkwin = scalePtr->tkwin;
int x, y, length, width;
- char valueString[PRINT_CHARS];
+ char valueString[TCL_DOUBLE_SPACE];
Tk_FontMetrics fm;
x = TkScaleValueToPixel(scalePtr, value);
@@ -535,7 +535,7 @@ TkpDisplayScale(
Tcl_Interp *interp = scalePtr->interp;
Pixmap pixmap;
int result;
- char string[PRINT_CHARS];
+ char string[TCL_DOUBLE_SPACE];
XRectangle drawnArea;
scalePtr->flags &= ~REDRAW_PENDING;