From 4fdc73733207bd69ff17bc8c150e026e35accb5b Mon Sep 17 00:00:00 2001 From: dkf Date: Fri, 9 Dec 2005 14:13:00 +0000 Subject: Fix [Bug 1374778] --- ChangeLog | 6 ++++++ generic/tclCmdIL.c | 22 ++++++++++++++++++---- tests/lsearch.test | 14 +++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index d51d147..d1085aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-12-09 Donal K. Fellows + + * 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-08 Jeff Hobbs * win/Makefile.in, win/makefile.vc: Add Win x64 and CE build support diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 4c83b5f..e61a42d 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -16,7 +16,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.85 2005/11/29 10:32:56 dkf Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.86 2005/12/09 14:13:00 dkf Exp $ */ #include "tclInt.h" @@ -3454,12 +3454,26 @@ Tcl_LsearchObjCmd(clientData, interp, objc, objv) } return result; } - if (offset > listc-1) { - offset = listc-1; - } if (offset < 0) { offset = 0; } + + /* + * 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) { + if (sortInfo.indexc > 1) { + ckfree((char *) sortInfo.indexv); + } + if (allMatches || inlineReturn) { + Tcl_ResetResult(interp); + } else { + Tcl_SetObjResult(interp, Tcl_NewIntObj(-1)); + } + return TCL_OK; + } } patObj = objv[objc - 1]; diff --git a/tests/lsearch.test b/tests/lsearch.test index a54c1a0..fcaa85b 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.17 2005/11/29 10:32:56 dkf Exp $ +# RCS: @(#) $Id: lsearch.test,v 1.18 2005/12/09 14:13:01 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -317,6 +317,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 -- cgit v0.12