From c9bb96468f1ed1e24b9aaa8df6f69cbba9665680 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 14 Aug 2020 13:07:38 +0000 Subject: tkConfig.c: protect usage of internalPtr when offset is TCL_INDEX_NONE. Backported from revised_text. Various minor changes in error-messages, also inspired by revised_text --- generic/tkConfig.c | 168 +++++++++++++++++++++++----------------------- generic/tkText.c | 2 +- generic/ttk/ttkLayout.c | 8 +-- generic/ttk/ttkProgress.c | 2 +- generic/ttk/ttkScale.c | 4 +- generic/ttk/ttkTreeview.c | 2 +- macosx/tkMacOSXTest.c | 2 +- tests/text.test | 4 +- 8 files changed, 95 insertions(+), 97 deletions(-) diff --git a/generic/tkConfig.c b/generic/tkConfig.c index d4ffa7c..859f2d0 100644 --- a/generic/tkConfig.c +++ b/generic/tkConfig.c @@ -1405,8 +1405,6 @@ Tk_RestoreSavedOptions( CLANG_ASSERT(internalPtr); switch (specPtr->type) { case TK_OPTION_BOOLEAN: - *((int *) internalPtr) = *((int *) ptr); - break; case TK_OPTION_INT: *((int *) internalPtr) = *((int *) ptr); break; @@ -1874,106 +1872,106 @@ GetObjectForOption( void *internalPtr; /* Points to internal value of option in * record. */ - internalPtr = (char *)recordPtr + optionPtr->specPtr->internalOffset; objPtr = NULL; - switch (optionPtr->specPtr->type) { - case TK_OPTION_BOOLEAN: - objPtr = Tcl_NewWideIntObj(*((int *) internalPtr)); - break; - case TK_OPTION_INT: - objPtr = Tcl_NewWideIntObj(*((int *) internalPtr)); - break; - case TK_OPTION_DOUBLE: - objPtr = Tcl_NewDoubleObj(*((double *) internalPtr)); - break; - case TK_OPTION_STRING: - objPtr = Tcl_NewStringObj(*((char **) internalPtr), -1); - break; - case TK_OPTION_STRING_TABLE: - objPtr = Tcl_NewStringObj(((char **) optionPtr->specPtr->clientData)[ - *((int *) internalPtr)], -1); - break; - case TK_OPTION_COLOR: { - XColor *colorPtr = *((XColor **) internalPtr); + if (optionPtr->specPtr->internalOffset != TCL_INDEX_NONE) { + internalPtr = (char *)recordPtr + optionPtr->specPtr->internalOffset; + switch (optionPtr->specPtr->type) { + case TK_OPTION_BOOLEAN: + case TK_OPTION_INT: + objPtr = Tcl_NewWideIntObj(*((int *) internalPtr)); + break; + case TK_OPTION_DOUBLE: + objPtr = Tcl_NewDoubleObj(*((double *) internalPtr)); + break; + case TK_OPTION_STRING: + objPtr = Tcl_NewStringObj(*((char **) internalPtr), -1); + break; + case TK_OPTION_STRING_TABLE: + objPtr = Tcl_NewStringObj(((char **) optionPtr->specPtr->clientData)[ + *((int *) internalPtr)], -1); + break; + case TK_OPTION_COLOR: { + XColor *colorPtr = *((XColor **) internalPtr); - if (colorPtr != NULL) { - objPtr = Tcl_NewStringObj(Tk_NameOfColor(colorPtr), -1); + if (colorPtr != NULL) { + objPtr = Tcl_NewStringObj(Tk_NameOfColor(colorPtr), -1); + } + break; } - break; - } - case TK_OPTION_FONT: { - Tk_Font tkfont = *((Tk_Font *) internalPtr); + case TK_OPTION_FONT: { + Tk_Font tkfont = *((Tk_Font *) internalPtr); - if (tkfont != NULL) { - objPtr = Tcl_NewStringObj(Tk_NameOfFont(tkfont), -1); + if (tkfont != NULL) { + objPtr = Tcl_NewStringObj(Tk_NameOfFont(tkfont), -1); + } + break; } - break; - } - case TK_OPTION_STYLE: { - Tk_Style style = *((Tk_Style *) internalPtr); + case TK_OPTION_STYLE: { + Tk_Style style = *((Tk_Style *) internalPtr); - if (style != NULL) { - objPtr = Tcl_NewStringObj(Tk_NameOfStyle(style), -1); + if (style != NULL) { + objPtr = Tcl_NewStringObj(Tk_NameOfStyle(style), -1); + } + break; } - break; - } - case TK_OPTION_BITMAP: { - Pixmap pixmap = *((Pixmap *) internalPtr); + case TK_OPTION_BITMAP: { + Pixmap pixmap = *((Pixmap *) internalPtr); - if (pixmap != None) { - objPtr = Tcl_NewStringObj( + if (pixmap != None) { + objPtr = Tcl_NewStringObj( Tk_NameOfBitmap(Tk_Display(tkwin), pixmap), -1); + } + break; } - break; - } - case TK_OPTION_BORDER: { - Tk_3DBorder border = *((Tk_3DBorder *) internalPtr); + case TK_OPTION_BORDER: { + Tk_3DBorder border = *((Tk_3DBorder *) internalPtr); - if (border != NULL) { - objPtr = Tcl_NewStringObj(Tk_NameOf3DBorder(border), -1); + if (border != NULL) { + objPtr = Tcl_NewStringObj(Tk_NameOf3DBorder(border), -1); + } + break; } - break; - } - case TK_OPTION_RELIEF: - objPtr = Tcl_NewStringObj(Tk_NameOfRelief(*((int *) internalPtr)), -1); - break; - case TK_OPTION_CURSOR: { - Tk_Cursor cursor = *((Tk_Cursor *) internalPtr); + case TK_OPTION_RELIEF: + objPtr = Tcl_NewStringObj(Tk_NameOfRelief(*((int *) internalPtr)), -1); + break; + case TK_OPTION_CURSOR: { + Tk_Cursor cursor = *((Tk_Cursor *) internalPtr); - if (cursor != NULL) { - objPtr = Tcl_NewStringObj( - Tk_NameOfCursor(Tk_Display(tkwin), cursor), -1); + if (cursor != NULL) { + objPtr = Tcl_NewStringObj( + Tk_NameOfCursor(Tk_Display(tkwin), cursor), -1); + } + break; } - break; - } - case TK_OPTION_JUSTIFY: - objPtr = Tcl_NewStringObj(Tk_NameOfJustify( - *((Tk_Justify *) internalPtr)), -1); - break; - case TK_OPTION_ANCHOR: - objPtr = Tcl_NewStringObj(Tk_NameOfAnchor( - *((Tk_Anchor *) internalPtr)), -1); - break; - case TK_OPTION_PIXELS: - objPtr = Tcl_NewWideIntObj(*((int *) internalPtr)); - break; - case TK_OPTION_WINDOW: { - Tk_Window tkwin = *((Tk_Window *) internalPtr); + case TK_OPTION_JUSTIFY: + objPtr = Tcl_NewStringObj(Tk_NameOfJustify( + *((Tk_Justify *) internalPtr)), -1); + break; + case TK_OPTION_ANCHOR: + objPtr = Tcl_NewStringObj(Tk_NameOfAnchor( + *((Tk_Anchor *) internalPtr)), -1); + break; + case TK_OPTION_PIXELS: + objPtr = Tcl_NewWideIntObj(*((int *) internalPtr)); + break; + case TK_OPTION_WINDOW: { + Tk_Window tkwin = *((Tk_Window *) internalPtr); - if (tkwin != NULL) { - objPtr = Tcl_NewStringObj(Tk_PathName(tkwin), -1); + if (tkwin != NULL) { + objPtr = Tcl_NewStringObj(Tk_PathName(tkwin), -1); + } + break; } - break; - } - case TK_OPTION_CUSTOM: { - const Tk_ObjCustomOption *custom = optionPtr->extra.custom; + case TK_OPTION_CUSTOM: { + const Tk_ObjCustomOption *custom = optionPtr->extra.custom; - objPtr = custom->getProc(custom->clientData, tkwin, (char *)recordPtr, - optionPtr->specPtr->internalOffset); - break; - } - default: - Tcl_Panic("bad option type in GetObjectForOption"); + objPtr = custom->getProc(custom->clientData, tkwin, (char *)recordPtr, + optionPtr->specPtr->internalOffset); + break; + } + default: + Tcl_Panic("bad option type in GetObjectForOption"); + } } if (objPtr == NULL) { objPtr = Tcl_NewObj(); diff --git a/generic/tkText.c b/generic/tkText.c index 119f229..d7d7102 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -1051,7 +1051,7 @@ TextWidgetObjCmd( badOption: Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "bad option \"%s\" must be -chars, -displaychars, " + "bad option \"%s\": must be -chars, -displaychars, " "-displayindices, -displaylines, -indices, -lines, -update, " "-xpixels, or -ypixels", Tcl_GetString(objv[i]))); Tcl_SetErrorCode(interp, "TK", "TEXT", "INDEX_OPTION", NULL); diff --git a/generic/ttk/ttkLayout.c b/generic/ttk/ttkLayout.c index 5e8c69c..a39ae2b 100644 --- a/generic/ttk/ttkLayout.c +++ b/generic/ttk/ttkLayout.c @@ -36,10 +36,10 @@ Ttk_NewBoxObj(Ttk_Box box) { Tcl_Obj *result[4]; - result[0] = Tcl_NewIntObj(box.x); - result[1] = Tcl_NewIntObj(box.y); - result[2] = Tcl_NewIntObj(box.width); - result[3] = Tcl_NewIntObj(box.height); + result[0] = Tcl_NewWideIntObj(box.x); + result[1] = Tcl_NewWideIntObj(box.y); + result[2] = Tcl_NewWideIntObj(box.width); + result[3] = Tcl_NewWideIntObj(box.height); return Tcl_NewListObj(4, result); } diff --git a/generic/ttk/ttkProgress.c b/generic/ttk/ttkProgress.c index 6e5875e..505748b 100644 --- a/generic/ttk/ttkProgress.c +++ b/generic/ttk/ttkProgress.c @@ -137,7 +137,7 @@ static void AnimateProgressProc(ClientData clientData) if (pb->progress.maxPhase) phase %= pb->progress.maxPhase; Tcl_DecrRefCount(pb->progress.phaseObj); - pb->progress.phaseObj = Tcl_NewIntObj(phase); + pb->progress.phaseObj = Tcl_NewWideIntObj(phase); Tcl_IncrRefCount(pb->progress.phaseObj); /* diff --git a/generic/ttk/ttkScale.c b/generic/ttk/ttkScale.c index a6bde9a..a2c5d59 100644 --- a/generic/ttk/ttkScale.c +++ b/generic/ttk/ttkScale.c @@ -376,8 +376,8 @@ ScaleCoordsCommand( if (r == TCL_OK) { Tcl_Obj *point[2]; XPoint pt = ValueToPoint(scalePtr, value); - point[0] = Tcl_NewIntObj(pt.x); - point[1] = Tcl_NewIntObj(pt.y); + point[0] = Tcl_NewWideIntObj(pt.x); + point[1] = Tcl_NewWideIntObj(pt.y); Tcl_SetObjResult(interp, Tcl_NewListObj(2, point)); } return r; diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c index ac6107b..d48a510 100644 --- a/generic/ttk/ttkTreeview.c +++ b/generic/ttk/ttkTreeview.c @@ -2125,7 +2125,7 @@ static int TreeviewIndexCommand( item = item->prev; } - Tcl_SetObjResult(interp, Tcl_NewIntObj(index)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(index)); return TCL_OK; } diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index 434504f..6cb0a13 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -126,7 +126,7 @@ MenuBarHeightObjCmd( if (height == 0) { height = (int) [[NSApp mainMenu] menuBarHeight]; } - Tcl_SetObjResult(interp, Tcl_NewIntObj(height)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(height)); return TCL_OK; } diff --git a/tests/text.test b/tests/text.test index 6d8e9bf..4a5c1b3 100644 --- a/tests/text.test +++ b/tests/text.test @@ -2068,7 +2068,7 @@ test text-10.2 {TextWidgetCmd procedure, "count" option} -setup { .t count blah 1.0 2.0 } -cleanup { destroy .t -} -returnCodes {error} -result {bad option "blah" must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels} +} -returnCodes {error} -result {bad option "blah": must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels} test text-10.3 {TextWidgetCmd procedure, "count" option} -setup { text .t } -body { @@ -2608,7 +2608,7 @@ test text-10.32 {TextWidgetCmd procedure, "count" option} -setup { .t count -lines 1.0 2.0 3.0 } -cleanup { destroy .t -} -returnCodes {error} -result {bad option "1.0" must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels} +} -returnCodes {error} -result {bad option "1.0": must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels} test text-10.33 {TextWidgetCmd procedure, "count" option} -setup { text .t } -body { -- cgit v0.12