diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2010-02-27 21:25:05 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2010-02-27 21:25:05 (GMT) |
commit | 298c4065cae4ab2fa1cf1c5a20eb5ee52530bc5a (patch) | |
tree | cd5830175f1d7d024ef1bca3861418f4a30875a1 /generic | |
parent | 8ed034378aeb3843ee2337f641f476fddba9543a (diff) | |
download | tcl-298c4065cae4ab2fa1cf1c5a20eb5ee52530bc5a.zip tcl-298c4065cae4ab2fa1cf1c5a20eb5ee52530bc5a.tar.gz tcl-298c4065cae4ab2fa1cf1c5a20eb5ee52530bc5a.tar.bz2 |
Only look for the needle when it fits in the haystack. [Bug 2960021]
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCmdMZ.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 1ff2138..70002b5 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.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: tclCmdMZ.c,v 1.163.2.5 2009/08/25 21:01:05 andreas_kupries Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.163.2.6 2010/02/27 21:25:05 dkf Exp $ */ #include "tclInt.h" @@ -1166,7 +1166,12 @@ StringFirstCmd( } } - if (length1 > 0) { + /* + * If the length of the needle is more than the length of the haystack, it + * cannot be contained in there so we can avoid searching. [Bug 2960021] + */ + + if (length1 > 0 && length1 <= length2) { register Tcl_UniChar *p, *end; end = ustring2 + length2 - length1 + 1; @@ -1269,7 +1274,12 @@ StringLastCmd( p = ustring2 + length2 - length1; } - if (length1 > 0) { + /* + * If the length of the needle is more than the length of the haystack, it + * cannot be contained in there so we can avoid searching. [Bug 2960021] + */ + + if (length1 > 0 && length1 <= length2) { for (; p >= ustring2; p--) { /* * Scan backwards to find the first character. |