diff options
Diffstat (limited to 'unix/tkUnixScale.c')
-rw-r--r-- | unix/tkUnixScale.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/unix/tkUnixScale.c b/unix/tkUnixScale.c index 71f9ea8..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: */ @@ -46,7 +50,7 @@ TkScale * TkpCreateScale( Tk_Window tkwin) { - return (TkScale *) ckalloc(sizeof(TkScale)); + return ckalloc(sizeof(TkScale)); } /* @@ -71,7 +75,7 @@ void TkpDestroyScale( TkScale *scalePtr) { - Tcl_EventuallyFree((ClientData) scalePtr, TCL_DYNAMIC); + Tcl_EventuallyFree(scalePtr, TCL_DYNAMIC); } /* @@ -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); @@ -537,6 +548,7 @@ TkpDisplayScale( int result; char string[TCL_DOUBLE_SPACE]; XRectangle drawnArea; + Tcl_DString buf; scalePtr->flags &= ~REDRAW_PENDING; if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) { @@ -547,24 +559,31 @@ TkpDisplayScale( * Invoke the scale's command if needed. */ - Tcl_Preserve((ClientData) scalePtr); + Tcl_Preserve(scalePtr); if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { - Tcl_Preserve((ClientData) interp); - sprintf(string, scalePtr->format, scalePtr->value); - result = Tcl_VarEval(interp, scalePtr->command, " ", string, - (char *) NULL); + Tcl_Preserve(interp); + 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); + Tcl_DStringAppend(&buf, string, -1); + result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0); + Tcl_DStringFree(&buf); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (command executed by scale)"); - Tcl_BackgroundError(interp); + Tcl_BackgroundException(interp, result); } - Tcl_Release((ClientData) interp); + Tcl_Release(interp); } scalePtr->flags &= ~INVOKE_COMMAND; if (scalePtr->flags & SCALE_DELETED) { - Tcl_Release((ClientData) scalePtr); + Tcl_Release(scalePtr); return; } - Tcl_Release((ClientData) scalePtr); + Tcl_Release(scalePtr); #ifndef TK_NO_DOUBLE_BUFFERING /* |