summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclExecute.c7
-rw-r--r--tests/expr.test6
3 files changed, 16 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index f1ceb9c..713131e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-07-26 Don Porter <dgp@users.sourceforge.net>
+
+ * generic/tclExecute.c: Corrected flawed overflow detection in
+ * tests/expr.test: INST_EXPON that caused [expr 2**64]
+ to return 0 instead of the same value as [expr 1<<64].
+
2006-07-24 Don Porter <dgp@users.sourceforge.net>
* win/tclWinSock.c: Correct un-initialized Tcl_DString. Thanks
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 0870219..5e12c95 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclExecute.c,v 1.239 2006/07/21 10:47:18 msofer Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.240 2006/07/26 21:56:34 dgp Exp $
*/
#include "tclInt.h"
@@ -4858,7 +4858,7 @@ TclExecuteByteCode(
w2 /= 2;
for (; w2>Tcl_LongAsWide(1) ; w1*=w1,w2/=2) {
wasNegative = (wResult < 0);
- if (w1 < 0) {
+ if (w1 <= 0) {
goto overflow;
}
if (w2 & 1) {
@@ -4869,6 +4869,9 @@ TclExecuteByteCode(
}
}
wasNegative = (wResult < 0);
+ if (w1 <= 0) {
+ goto overflow;
+ }
wResult *= w1;
if (wasNegative != (wResult < 0)) {
goto overflow;
diff --git a/tests/expr.test b/tests/expr.test
index 980f0b9..faca569 100644
--- a/tests/expr.test
+++ b/tests/expr.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: expr.test,v 1.55 2006/07/05 05:34:45 dgp Exp $
+# RCS: @(#) $Id: expr.test,v 1.56 2006/07/26 21:56:35 dgp Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2.1
@@ -1032,6 +1032,10 @@ test expr-23.39 {INST_EXPON: big integer} {
expr 1[string repeat 0 30]**2
} 1[string repeat 0 60]
test expr-23.40 {INST_EXPON: overflow to big integer} {expr {(-10)**3}} -1000
+test expr-23.41 {INST_EXPON: overflow to big integer} {expr 2**64} [expr 1<<64]
+test expr-23.41 {INST_EXPON: overflow to big integer} {expr 4**32} [expr 1<<64]
+test expr-23.41 {INST_EXPON: overflow to big integer} {expr 16**16} [expr 1<<64]
+test expr-23.41 {INST_EXPON: overflow to big integer} {expr 256**8} [expr 1<<64]
# Some compilers get this wrong; ensure that we work around it correctly
test expr-24.1 {expr edge cases; shifting} {expr int(5)>>32} 0