summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2007-03-01 10:16:09 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2007-03-01 10:16:09 (GMT)
commit44ebec67f366b1da8cc1609b93847b2c6a590749 (patch)
tree3a2cdb549c109b3cc5f7794e2dcfb3988d7f35da
parent4ced9366453c96f6237ff479dff2fc80bd0e18d9 (diff)
downloadtcl-44ebec67f366b1da8cc1609b93847b2c6a590749.zip
tcl-44ebec67f366b1da8cc1609b93847b2c6a590749.tar.gz
tcl-44ebec67f366b1da8cc1609b93847b2c6a590749.tar.bz2
Fix [Bug 1671138]
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclCompCmds.c14
-rw-r--r--tests/foreach.test12
3 files changed, 30 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index ff709a9..2e8a2d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-03-01 Donal K. Fellows <donal.k.fellows@man.ac.uk>
+
+ * generic/tclCompCmds.c (TclCompileForeachCmd): Prevent an unexpected
+ * tests/foreach.test (foreach-9.1): infinite loop when the
+ variable list is empty and the foreach is compiled. [Bug 1671138]
+
2007-02-22 Andreas Kupries <andreask@activestate.com>
* tests/pkg.test: Added tests for the case of an alpha package
diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c
index 0737ab2..9c20bac 100644
--- a/generic/tclCompCmds.c
+++ b/generic/tclCompCmds.c
@@ -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: tclCompCmds.c,v 1.39.2.4 2006/11/28 22:20:00 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclCompCmds.c,v 1.39.2.5 2007/03/01 10:16:10 dkf Exp $
*/
#include "tclInt.h"
@@ -894,6 +894,18 @@ TclCompileForeachCmd(interp, parsePtr, envPtr)
goto done;
}
numVars = varcList[loopIndex];
+
+ /*
+ * If the variable list is empty, we can enter an infinite
+ * loop when the interpreted version would not. Take care to
+ * ensure this does not happen. [Bug 1671138]
+ */
+
+ if (numVars == 0) {
+ code = TCL_ERROR;
+ goto done;
+ }
+
for (j = 0; j < numVars; j++) {
CONST char *varName = varvList[loopIndex][j];
if (!TclIsLocalScalar(varName, (int) strlen(varName))) {
diff --git a/tests/foreach.test b/tests/foreach.test
index 0ab6340..ee90ce2 100644
--- a/tests/foreach.test
+++ b/tests/foreach.test
@@ -10,7 +10,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: foreach.test,v 1.8.8.1 2003/03/27 13:11:01 dkf Exp $
+# RCS: @(#) $Id: foreach.test,v 1.8.8.2 2007/03/01 10:16:10 dkf Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
@@ -233,6 +233,16 @@ test foreach-7.1 {delayed substitution of body} {
foo
} {0}
+# [Bug 1671138]; infinite loop with empty var list in bytecompiled version
+test foreach-9.1 {compiled empty var list} {
+ proc foo {} {
+ foreach {} x {
+ error "reached body"
+ }
+ }
+ list [catch { foo } msg] $msg
+} {1 {foreach varlist is empty}}
+
# cleanup
catch {unset a}
catch {unset x}