Index: ChangeLog =================================================================== RCS file: /cvsroot/tcl/tcl/ChangeLog,v retrieving revision 1.372 diff -u -r1.372 ChangeLog --- ChangeLog 2001/03/02 15:31:15 1.372 +++ ChangeLog 2001/03/06 14:13:26 @@ -1,3 +1,13 @@ +2001-03-06 Donal K. Fellows + + * generic/tclVar.c (Tcl_UnsetObjCmd): Rewrote argument parser to + avoid a read off the end of the argument array that could occur + when executing something like [unset -nocomplain] was executed. + Improved the error message given when too few arguments are given + (-nocomplain should obviously be *before* --, not after it) and + also modified the test suite to take account of that and the + documentation to use the same improvement. + 2001-03-02 Donal K. Fellows * generic/tclExecute.c (TclExecuteByteCode): Fixed bug that could Index: doc/unset.n =================================================================== RCS file: /cvsroot/tcl/tcl/doc/unset.n,v retrieving revision 1.4 diff -u -r1.4 unset.n --- doc/unset.n 2000/09/07 14:27:52 1.4 +++ doc/unset.n 2001/03/06 14:13:26 @@ -15,7 +15,7 @@ .SH NAME unset \- Delete variables .SH SYNOPSIS -\fBunset \fR?\fI\-\-\fR? ?\fI\-nocomplain\fR? ?\fIname name name ...\fR? +\fBunset \fR?\fI\-nocomplain\fR? ?\fI\-\-\fR? ?\fIname name name ...\fR? .BE .SH DESCRIPTION @@ -31,9 +31,9 @@ .VS 8.4 If \fI\-nocomplain\fR is specified as the first argument, any possible errors are suppressed. The option may not be abbreviated, in order to -disambiguate it from possible variable names. \fI\-\-\fR may be specified -prior to \fI\-nocomplain\fR to prevent it from being interpreted as an -option. +disambiguate it from possible variable names. The option \fI\-\-\fR +indicates the end of the options, and should be used if you wish to +remove a variable with the same name as any of the options. .VE 8.4 If an error occurs, any variables after the named one causing the error not deleted. An error can occur when the named variable doesn't exist, or the Index: generic/tclVar.c =================================================================== RCS file: /cvsroot/tcl/tcl/generic/tclVar.c,v retrieving revision 1.27 diff -u -r1.27 tclVar.c --- generic/tclVar.c 2000/11/17 11:06:53 1.27 +++ generic/tclVar.c 2001/03/06 14:13:27 @@ -2611,23 +2611,29 @@ if (objc < 2) { Tcl_WrongNumArgs(interp, 1, objv, - "?--? ?-nocomplain? ?varName varName ...?"); + "?-nocomplain? ?--? ?varName varName ...?"); return TCL_ERROR; } /* - * Very simple, restrictive argument parsing. The only options are - * -- and -nocomplain (which must come first to be an option). + * Simple, restrictive argument parsing. The only options are -- + * and -nocomplain (which must come first and be given exactly to + * be an option). */ i = 1; name = TclGetString(objv[i]); - if ((name[0] == '-') && (strcmp("-nocomplain", name) == 0)) { - flags = 0; - i++; - name = TclGetString(objv[i]); - } - if ((name[0] == '-') && (strcmp("--", name) == 0)) { - i++; + if (name[0] == '-') { + if (strcmp("-nocomplain", name) == 0) { + i++; + if (i == objc) { + return TCL_OK; + } + flags = 0; + name = TclGetString(objv[i]); + } + if (strcmp("--", name) == 0) { + i++; + } } for (; i < objc; i++) { Index: tests/set-old.test =================================================================== RCS file: /cvsroot/tcl/tcl/tests/set-old.test,v retrieving revision 1.12 diff -u -r1.12 set-old.test --- tests/set-old.test 2000/08/21 01:37:51 1.12 +++ tests/set-old.test 2001/03/06 14:13:27 @@ -204,7 +204,7 @@ } {0 0 0 1} test set-old-7.2 {unset command} { list [catch {unset} msg] $msg -} {1 {wrong # args: should be "unset ?--? ?-nocomplain? ?varName varName ...?"}} +} {1 {wrong # args: should be "unset ?-nocomplain? ?--? ?varName varName ...?"}} test set-old-7.3 {unset command} { catch {unset a} list [catch {unset a} msg] $msg