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 | 80ecae58c28399a9f8bebb3d8a35d898e190ec98 (patch) | |
tree | cd5830175f1d7d024ef1bca3861418f4a30875a1 /generic | |
parent | 0fec06d7684db92a4ee5910609fa1cf0298228a4 (diff) | |
download | tcl-80ecae58c28399a9f8bebb3d8a35d898e190ec98.zip tcl-80ecae58c28399a9f8bebb3d8a35d898e190ec98.tar.gz tcl-80ecae58c28399a9f8bebb3d8a35d898e190ec98.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. |