From dda6e2358ef98e30c75799b489a68a0805e391b2 Mon Sep 17 00:00:00 2001 From: dkf Date: Tue, 5 Jan 2010 09:44:53 +0000 Subject: [Bug 220950]: Don't delete the last menu entry when it is obvious that is not what was intended. --- ChangeLog | 6 ++++++ generic/tkMenu.c | 15 +++++++++++++-- tests/menu.test | 13 ++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ae8efc..d3e2a58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-05 Donal K. Fellows + + * generic/tkMenu.c (MenuWidgetObjCmd): [Bug 220950]: Do not delete + menu entries if the first index to delete is explicitly after the last + index of existing entries. + 2010-01-04 Pat Thoyts * library/dialog.tcl: Backported fix for tk_dialog binding diff --git a/generic/tkMenu.c b/generic/tkMenu.c index 98f3f60..7af304e 100644 --- a/generic/tkMenu.c +++ b/generic/tkMenu.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMenu.c,v 1.41.2.3 2009/12/30 00:29:38 patthoyts Exp $ + * RCS: @(#) $Id: tkMenu.c,v 1.41.2.4 2010/01/05 09:44:54 dkf Exp $ */ /* @@ -777,7 +777,18 @@ MenuWidgetObjCmd( Tcl_WrongNumArgs(interp, 2, objv, "first ?last?"); goto error; } - if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &first) != TCL_OK) { + + /* + * If 'first' explicitly refers to past the end of the menu, we don't + * do anything. [Bug 220950] + */ + + if (isdigit(UCHAR(Tcl_GetString(objv[2])[0])) + && Tcl_GetIntFromObj(NULL, objv[2], &first) == TCL_OK) { + if (first >= menuPtr->numEntries) { + goto done; + } + } else if (TkGetMenuIndex(interp,menuPtr,objv[2],0,&first) != TCL_OK){ goto error; } if (objc == 3) { diff --git a/tests/menu.test b/tests/menu.test index a34171c..0fd4113 100644 --- a/tests/menu.test +++ b/tests/menu.test @@ -5,7 +5,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: menu.test,v 1.20.4.2 2010/01/03 00:42:02 patthoyts Exp $ +# RCS: @(#) $Id: menu.test,v 1.20.4.3 2010/01/05 09:44:54 dkf Exp $ package require tcltest 2.1 eval tcltest::configure $argv @@ -681,6 +681,17 @@ test menu-3.29 {MenuWidgetCmd procedure, "delete" option} { .m1 activate 3 list [catch {.m1 delete 1} msg] $msg [destroy .m1] } {0 {} {}} +test menu-3.29+1 {MenuWidgetCmd, "delete", Bug 220950} -setup { + destroy .m1 +} -body { + menu .m1 + .m1 add command -label "bogus" + .m1 add command -label "ok" + .m1 delete 10 20 + .m1 entrycget last -label +} -cleanup { + destroy .m1 +} -result ok test menu-3.30 {MenuWidgetCmd procedure, "entrycget" option} { catch {destroy .m1} menu .m1 -- cgit v0.12