diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2005-12-09 14:39:19 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2005-12-09 14:39:19 (GMT) |
commit | 935e1e7bff4e2328bdf256ef524c4a6a3aa9947e (patch) | |
tree | da3986461468c87bac28425373ea0a11e510ddb2 | |
parent | 268ee946f3eb31ba016fd1d3275e202b7617dbe1 (diff) | |
download | tcl-935e1e7bff4e2328bdf256ef524c4a6a3aa9947e.zip tcl-935e1e7bff4e2328bdf256ef524c4a6a3aa9947e.tar.gz tcl-935e1e7bff4e2328bdf256ef524c4a6a3aa9947e.tar.bz2 |
Fix [Bug 1374778]
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | generic/tclCmdIL.c | 15 | ||||
-rw-r--r-- | tests/lsearch.test | 14 |
3 files changed, 32 insertions, 3 deletions
@@ -1,3 +1,9 @@ +2005-12-09 Donal K. Fellows <donal.k.fellows@manchester.ac.uk> + + * tests/lsearch.test (lsearch-10.8..10): If the -start is off the end, + * generic/tclCmdIL.c (Tcl_LsearchObjCmd): searching should find + nothing at all. [Bug 1374778] + 2005-12-05 Daniel Steffen <das@users.sourceforge.net> *** 8.4.12 TAGGED FOR RELEASE *** diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 7a232a6..a867272 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdIL.c,v 1.47.2.8 2005/11/29 10:32:31 dkf Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.47.2.9 2005/12/09 14:39:25 dkf Exp $ */ #include "tclInt.h" @@ -3066,8 +3066,19 @@ Tcl_LsearchObjCmd(clientData, interp, objc, objv) if (result != TCL_OK) { return result; } + + /* + * If the search started past the end of the list, we just return a + * "did not match anything at all" result straight away. [Bug 1374778] + */ + if (offset > listc-1) { - offset = listc-1; + if (allMatches || inlineReturn) { + Tcl_ResetResult(interp); + } else { + Tcl_SetObjResult(interp, Tcl_NewIntObj(-1)); + } + return TCL_OK; } if (offset < 0) { offset = 0; diff --git a/tests/lsearch.test b/tests/lsearch.test index 47d4ffc..86884c4 100644 --- a/tests/lsearch.test +++ b/tests/lsearch.test @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: lsearch.test,v 1.10.2.2 2005/11/29 10:32:31 dkf Exp $ +# RCS: @(#) $Id: lsearch.test,v 1.10.2.3 2005/12/09 14:39:25 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -293,6 +293,18 @@ test lsearch-10.7 {offset searching with an empty list} { # Stop bug #694232 from reocurring lsearch -start 0 {} x } -1 +test lsearch-10.8 {offset searching past the end of the list} { + # Stop [Bug 1374778] from reoccurring + lsearch -start 10 {a b c} c +} -1 +test lsearch-10.9 {offset searching past the end of the list} { + # Stop [Bug 1374778] from reoccurring + lsearch -start 10 -all {a b c} c +} {} +test lsearch-10.10 {offset searching past the end of the list} { + # Stop [Bug 1374778] from reoccurring + lsearch -start 10 -inline {a b c} c +} {} test lsearch-11.1 {negated searches} { lsearch -not {a a a b a a a} a |