summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2005-08-05 18:50:20 (GMT)
committerKevin B Kenny <kennykb@acm.org>2005-08-05 18:50:20 (GMT)
commit33f99a107c785f2a316908111b390ec9bed82a6a (patch)
tree198e2c38a17a43259d35c7f36b254a93b0182e76
parentc411bb62c886240f5cbd8f59c5c3c8ff5c9f5754 (diff)
downloadtcl-33f99a107c785f2a316908111b390ec9bed82a6a.zip
tcl-33f99a107c785f2a316908111b390ec9bed82a6a.tar.gz
tcl-33f99a107c785f2a316908111b390ec9bed82a6a.tar.bz2
Handle abs(-0x80000000) [Bug 1241572]
-rw-r--r--ChangeLog12
-rw-r--r--generic/tclBasic.c12
-rw-r--r--tests/expr.test6
3 files changed, 23 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 6569bf9..099c47f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,14 @@
2005-08-05 Kevin Kenny <kennykb@users.sourceforge.net>
- * win/makefile.vc: Removed unused file ldAout.tcl.
- * win/makefile.bc: [Bug #1244361]
+ * win/makefile.vc: Removed unused file ldAout.tcl.
+ * win/makefile.bc: [Bug #1244361]
- * tests/binary.test: Cleaned up testing for scanning of NaN.
- [Bug #1246264]
+ * tests/binary.test: Cleaned up testing for scanning of NaN.
+ [Bug #1246264]
+
+ * generic/tclBasic.c (ExprAbsFunc): Added code to handle the
+ * tests/expr.test (expr-38.1): corner case of applying
+ 'abs' to the smallest 32-bit integer. [Bug #1241572]
2005-08-04 Andreas Kupries <andreask@activestate.com>
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 5c36bbc..4414c52 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -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: tclBasic.c,v 1.164 2005/07/26 17:06:12 dgp Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.165 2005/08/05 18:50:27 kennykb Exp $
*/
#include "tclInt.h"
@@ -5091,12 +5091,20 @@ ExprAbsFunc(clientData, interp, objc, objv)
if (i < 0) {
iResult = -i;
if (iResult < 0) {
- /* FIXME: This should promote to wide! */
+#ifdef TCL_WIDE_INT_IS_LONG
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"integer value too large to represent", -1));
Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW",
"integer value too large to represent", (char *) NULL);
return TCL_ERROR;
+#else
+ /*
+ * Special case: abs(MIN_INT) must promote to wide.
+ */
+ TclNewWideIntObj(oResult, -(Tcl_WideInt) i);
+ Tcl_SetObjResult(interp, oResult);
+ return TCL_OK;
+#endif
}
} else {
iResult = i;
diff --git a/tests/expr.test b/tests/expr.test
index 1aad141..89ac635 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.37 2005/07/28 18:42:28 dgp Exp $
+# RCS: @(#) $Id: expr.test,v 1.38 2005/08/05 18:50:30 kennykb Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2.1
@@ -6453,6 +6453,10 @@ test expr-37.14 {expr edge cases} {wideIs64bit} {
} {1 * -9223372036854775806 + -2 = -9223372036854775808}
+test expr-38.1 {abs of smallest 32-bit integer [Bug 1241572]} {wideIs64bit} {
+ expr {abs(-2147483648)}
+} 2147483648
+
# cleanup
if {[info exists a]} {
unset a