From cce4368acee1315cdc42e9d8c5db59a8f479edf7 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 15 Feb 2018 17:21:46 +0000 Subject: Revert recent commit that changed behavior of TclGetIntForIndex() for a small subset of cases of overflow in index arithmetic. This changed the public behavior of indexes. I favor what's being done. I only want to do the complete work on a feature branch (coming soon), and consider what aspects may benefit from a TIP, and how we should future-proof the work against expanding ranges for valid index values in Tcl 9. This touches on issues partially raised in TIP 297. --- generic/tclUtil.c | 11 +---------- tests/util.test | 6 ------ 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index e90477f..9557aac 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3585,16 +3585,7 @@ TclGetIntForIndex( * be converted to one, use it. */ - Tcl_WideInt value = endValue + objPtr->internalRep.wideValue; - if (endValue > 0 && value < objPtr->internalRep.wideValue) { - *indexPtr = INT_MAX; /* numerical overflow */ - } else if (value < INT_MIN || (endValue < 0 && value > objPtr->internalRep.wideValue)) { - *indexPtr = INT_MIN; /* numerical underflow or value < INT_MIN */ - } else if (value > INT_MAX) { - *indexPtr = INT_MAX;/* value > INT_MAX */ - } else { - *indexPtr = (int) value; - } + *indexPtr = endValue + (int)objPtr->internalRep.wideValue; return TCL_OK; } diff --git a/tests/util.test b/tests/util.test index d186523..35fc642 100644 --- a/tests/util.test +++ b/tests/util.test @@ -729,12 +729,6 @@ test util-9.43 {TclGetIntForIndex} -body { test util-9.44 {TclGetIntForIndex} -body { string index a 0+1000000000000 } -returnCodes error -match glob -result * -test util-9.45 {TclGetIntForIndex} { - string index abcd end+2305843009213693950 -} {} -test util-9.46 {TclGetIntForIndex} { - string index abcd end+4294967294 -} {} test util-10.1 {Tcl_PrintDouble - rounding} {ieeeFloatingPoint} { convertDouble 0x0000000000000000 -- cgit v0.12