diff options
author | hobbs <hobbs> | 2006-04-05 20:54:57 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2006-04-05 20:54:57 (GMT) |
commit | 636d1fed7fa814e48effbb3957c30157b559069b (patch) | |
tree | 87b817c26e91bf9f461be17eef696a844d18f48a | |
parent | 45487b682e8ca5a466d577fbf600b40f7962d281 (diff) | |
download | tk-636d1fed7fa814e48effbb3957c30157b559069b.zip tk-636d1fed7fa814e48effbb3957c30157b559069b.tar.gz tk-636d1fed7fa814e48effbb3957c30157b559069b.tar.bz2 |
* tests/grid.test: fix segfault on empty or "all" index list
* generic/tkGrid.c (GridRowColumnConfigureCommand): [Bug 1422430]
-rw-r--r-- | generic/tkGrid.c | 63 | ||||
-rw-r--r-- | tests/grid.test | 32 |
2 files changed, 67 insertions, 28 deletions
diff --git a/generic/tkGrid.c b/generic/tkGrid.c index 2b5dfef..fc68c5b 100644 --- a/generic/tkGrid.c +++ b/generic/tkGrid.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkGrid.c,v 1.42 2006/01/11 19:53:47 pspjuth Exp $ + * RCS: @(#) $Id: tkGrid.c,v 1.43 2006/04/05 20:54:58 hobbs Exp $ */ #include "tkInt.h" @@ -946,15 +946,24 @@ GridRowColumnConfigureCommand(tkwin, interp, objc, objv) } string = Tcl_GetString(objv[1]); - masterPtr = GetGrid(master); slotType = (*string == 'c') ? COLUMN : ROW; + if (lObjc == 0) { + Tcl_AppendResult(interp, "no ", + (slotType == COLUMN) ? "column" : "row", + " indices specified", (char *) NULL); + return TCL_ERROR; + } + + masterPtr = GetGrid(master); first = 0; /* lint */ last = 0; /* lint */ if ((objc == 4) || (objc == 5)) { if (lObjc != 1) { - Tcl_AppendResult(interp, Tcl_GetString(objv[3]), - " must be a single element.", NULL); + Tcl_AppendResult(interp, Tcl_GetString(objv[0]), " ", + Tcl_GetString(objv[1]), + ": must specify a single element on retrieval", + (char *) NULL); return TCL_ERROR; } if (Tcl_GetIntFromObj(interp, lObjv[0], &slot) != TCL_OK) { @@ -1038,6 +1047,10 @@ GridRowColumnConfigureCommand(tkwin, interp, objc, objv) last = slot; slavePtr = NULL; } else if (strcmp(Tcl_GetString(lObjv[j]), "all") == 0) { + /* + * Reset any lingering error from e.g GetInt. + */ + Tcl_ResetResult(interp); slavePtr = masterPtr->slavePtr; if (slavePtr == NULL) { continue; @@ -1049,9 +1062,9 @@ GridRowColumnConfigureCommand(tkwin, interp, objc, objv) * Is it gridded in this master? */ + Tcl_ResetResult(interp); slavePtr = GetGrid(slave); if (slavePtr->masterPtr != masterPtr) { - Tcl_ResetResult(interp); Tcl_AppendResult(interp, Tcl_GetString(objv[0]), " ", Tcl_GetString(objv[1]), ": the window \"", Tcl_GetString(lObjv[j]), "\" is not managed by \"", @@ -1067,12 +1080,6 @@ GridRowColumnConfigureCommand(tkwin, interp, objc, objv) } /* - * Reset any lingering error from e.g GetInt. - */ - - Tcl_ResetResult(interp); - - /* * The outer loop is only to handle "all". */ @@ -1156,25 +1163,27 @@ GridRowColumnConfigureCommand(tkwin, interp, objc, objv) /* * We changed a property, re-arrange the table, and check for constraint - * shrinkage. + * shrinkage. A null slotPtr will occur for 'all' checks. */ - if (slotType == ROW) { - int last = masterPtr->masterDataPtr->rowMax - 1; - while ((last >= 0) && (slotPtr[last].weight == 0) - && (slotPtr[last].pad == 0) && (slotPtr[last].minSize == 0) - && (slotPtr[last].uniform == NULL)) { - last--; - } - masterPtr->masterDataPtr->rowMax = last+1; - } else { - int last = masterPtr->masterDataPtr->columnMax - 1; - while ((last >= 0) && (slotPtr[last].weight == 0) - && (slotPtr[last].pad == 0) && (slotPtr[last].minSize == 0) - && (slotPtr[last].uniform == NULL)) { - last--; + if (slotPtr != NULL) { + if (slotType == ROW) { + int last = masterPtr->masterDataPtr->rowMax - 1; + while ((last >= 0) && (slotPtr[last].weight == 0) + && (slotPtr[last].pad == 0) && (slotPtr[last].minSize == 0) + && (slotPtr[last].uniform == NULL)) { + last--; + } + masterPtr->masterDataPtr->rowMax = last+1; + } else { + int last = masterPtr->masterDataPtr->columnMax - 1; + while ((last >= 0) && (slotPtr[last].weight == 0) + && (slotPtr[last].pad == 0) && (slotPtr[last].minSize == 0) + && (slotPtr[last].uniform == NULL)) { + last--; + } + masterPtr->masterDataPtr->columnMax = last + 1; } - masterPtr->masterDataPtr->columnMax = last + 1; } if (masterPtr->abortPtr != NULL) { diff --git a/tests/grid.test b/tests/grid.test index 0428eb4..c58d442 100644 --- a/tests/grid.test +++ b/tests/grid.test @@ -5,7 +5,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: grid.test,v 1.26 2005/04/03 15:21:49 pspjuth Exp $ +# RCS: @(#) $Id: grid.test,v 1.27 2006/04/05 20:54:57 hobbs Exp $ package require tcltest 2.1 eval tcltest::configure $argv @@ -751,6 +751,36 @@ test grid-10.26 {column/row configure} { } {-minsize 0 -pad 0 -uniform {} -weight 0} grid_reset 10.26 +test grid-10.30 {column/row configure - no indices} { + # Bug 1422430 + set t [toplevel .test] + set res [list [catch {grid columnconfigure $t "" -weight 1} msg] $msg] + destroy $t + set res +} {1 {no column indices specified}} + +test grid-10.31 {column/row configure - no indices} { + set t [toplevel .test] + set res [list [catch {grid rowconfigure $t "" -weight 1} msg] $msg] + destroy $t + set res +} {1 {no row indices specified}} + +test grid-10.32 {column/row configure - invalid indices} { + list [catch {grid columnconfigure . {0 1 2} -weight} msg] $msg +} {1 {grid columnconfigure: must specify a single element on retrieval}} + +test grid-10.33 {column/row configure - invalid indices} { + list [catch {grid rowconfigure . {0 1 2} -weight} msg] $msg +} {1 {grid rowconfigure: must specify a single element on retrieval}} + +test grid-10.34 {column/row configure - empty 'all' configure} { + # Bug 1422430 + set t [toplevel .test] + grid rowconfigure $t all -weight 1 + destroy $t +} {} + # auto-placement tests test grid-11.1 {default widget placement} { |