summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdMZ.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2010-02-27 19:02:25 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2010-02-27 19:02:25 (GMT)
commitfbada465b441596587db58a5972e6acc516208f2 (patch)
treea38afc9c18be0048ff5b566aab8a4436f176e45a /generic/tclCmdMZ.c
parent82facaaadc38055a533bb63ecd26a98eccac0373 (diff)
downloadtcl-fbada465b441596587db58a5972e6acc516208f2.zip
tcl-fbada465b441596587db58a5972e6acc516208f2.tar.gz
tcl-fbada465b441596587db58a5972e6acc516208f2.tar.bz2
Only look for the needle when it fits in the haystack. [Bug 2960021]
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r--generic/tclCmdMZ.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index 5ec25b3..af97570 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.201 2010/02/24 10:45:04 dkf Exp $
+ * RCS: @(#) $Id: tclCmdMZ.c,v 1.202 2010/02/27 19:02:26 dkf Exp $
*/
#include "tclInt.h"
@@ -1208,7 +1208,12 @@ StringFirstCmd(
}
}
- if (needleLen > 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 (needleLen > 0 && needleLen <= haystackLen) {
register Tcl_UniChar *p, *end;
end = haystackStr + haystackLen - needleLen + 1;
@@ -1313,7 +1318,12 @@ StringLastCmd(
p = haystackStr + haystackLen - needleLen;
}
- if (needleLen > 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 (needleLen > 0 && needleLen <= haystackLen) {
for (; p >= haystackStr; p--) {
/*
* Scan backwards to find the first character.