summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--generic/tclExecute.c32
-rw-r--r--tests/expr-old.test9
3 files changed, 35 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 8fed143..708fcab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2002-04-15 Miguel Sofer <msofer@users.sourceforge.net>
+
+ * generic/tclExecute.c:
+ * tests/expr-old.test: fix for [Bug #542588] (Phil Ehrens), where
+ "too large integers" were reported as "floating-point value" in
+ [expr] error messages.
+
2002-04-17 Don Porter <dgp@users.sourceforge.net>
* doc/tcltest.n: Removed [saveState] and [restoreState] from
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index fd369b2..f6d2ea2 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.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: tclExecute.c,v 1.52 2002/04/15 17:32:18 msofer Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.53 2002/04/18 13:04:20 msofer Exp $
*/
#include "tclInt.h"
@@ -4569,25 +4569,33 @@ IllegalExprOperandType(interp, pc, opndPtr)
operatorStrings[opCode - INST_LOR], "\"", (char *) NULL);
} else {
char *msg = "non-numeric string";
- if (opndPtr->typePtr != &tclDoubleType) {
+ char *s;
+ int length;
+
+ s = Tcl_GetStringFromObj(opndPtr, &length);
+ if (TclLooksLikeInt(s, length)) {
+ /*
+ * If something that looks like an integer appears here, then
+ * it *must* be a bad octal or too large to represent [Bug 542588].
+ */
+
+ if (TclCheckBadOctal(NULL, Tcl_GetString(opndPtr))) {
+ msg = "invalid octal number";
+ } else {
+ msg = "integer value too large to represent";
+ Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW",
+ "integer value too large to represent", (char *) NULL);
+ }
+ } else {
/*
* See if the operand can be interpreted as a double in order to
* improve the error message.
*/
- char *s = TclGetString(opndPtr);
double d;
if (Tcl_GetDouble((Tcl_Interp *) NULL, s, &d) == TCL_OK) {
- /*
- * Make sure that what appears to be a double
- * (ie 08) isn't really a bad octal
- */
- if (TclCheckBadOctal(NULL, TclGetString(opndPtr))) {
- msg = "invalid octal number";
- } else {
- msg = "floating-point value";
- }
+ msg = "floating-point value";
}
}
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "can't use ",
diff --git a/tests/expr-old.test b/tests/expr-old.test
index 6ed4446..3cf9959 100644
--- a/tests/expr-old.test
+++ b/tests/expr-old.test
@@ -13,7 +13,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-old.test,v 1.13 2001/12/06 10:59:17 dkf Exp $
+# RCS: @(#) $Id: expr-old.test,v 1.14 2002/04/18 13:04:20 msofer Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
@@ -934,6 +934,13 @@ test expr-old-36.10 {ExprLooksLikeInt procedure} {nonPortable unixOnly} {
list [catch {expr 78e} msg] $msg
} {1 {syntax error in expression "78e"}}
+# test for [Bug #542588]
+test expr-old-36.11 {ExprLooksLikeInt procedure} {
+ # define a "too large integer"; this one works also for 64bit arith
+ set x 665802003400000000000000
+ list [catch {expr {$x+1}} msg] $msg
+} {1 {can't use integer value too large to represent as operand of "+"}}
+
if {[info commands testexprlong] == {}} {
puts "This application hasn't been compiled with the \"testexprlong\""
puts "command, so I can't test Tcl_ExprLong etc."