diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2024-06-06 10:39:31 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2024-06-06 10:39:31 (GMT) |
| commit | c12e4b6cfe9d4b18e89bb8162766fe660722f48f (patch) | |
| tree | 3a8521ee3816c25eceb1e02abfd6aa3746fe7be3 | |
| parent | b54632928e8d3ebda479a7e8e56fa3b53a22f1ce (diff) | |
| parent | 43d2194943b8bb2c3080092a8219e3923b51f9bf (diff) | |
| download | tcl-c12e4b6cfe9d4b18e89bb8162766fe660722f48f.zip tcl-c12e4b6cfe9d4b18e89bb8162766fe660722f48f.tar.gz tcl-c12e4b6cfe9d4b18e89bb8162766fe660722f48f.tar.bz2 | |
Fix [57daa91ea]: Tcl_GetIntForIndex handling of n-m (m > n). With testcases.
| -rw-r--r-- | generic/tclUtil.c | 10 | ||||
| -rw-r--r-- | tests/indexObj.test | 24 |
2 files changed, 16 insertions, 18 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c index e82eea2..b87b5d6 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3706,18 +3706,12 @@ GetEndOffsetFromObj( * as endValue will have to adjust accordingly. */ *widePtr = (endValue == -1) ? WIDE_MAX : endValue + 1; - } else if (offset == WIDE_MIN) { - /* -1 - position before first */ - *widePtr = -1; } else if (offset < 0) { /* end-(n-1) - Different signs, sum cannot overflow */ *widePtr = endValue + offset + 1; - } else if (offset < WIDE_MAX) { - /* 0:WIDE_MAX-1 - plain old index. */ - *widePtr = offset; } else { - /* Huh, what case remains here? */ - *widePtr = WIDE_MAX; + /* 0:WIDE_MAX - plain old index. */ + *widePtr = offset; } return TCL_OK; diff --git a/tests/indexObj.test b/tests/indexObj.test index cf0f7df..c3f0676 100644 --- a/tests/indexObj.test +++ b/tests/indexObj.test @@ -20,7 +20,6 @@ testConstraint testindexobj [llength [info commands testindexobj]] testConstraint testgetintforindex [llength [info commands testgetintforindex]] testConstraint testparseargs [llength [info commands testparseargs]] testConstraint has64BitLengths [expr {$tcl_platform(pointerSize) == 8}] -testConstraint has32BitLengths [expr {$tcl_platform(pointerSize) == 4}] test indexObj-1.1 {exact match} testindexobj { testindexobj 1 1 xyz abc def xyz alm @@ -228,19 +227,24 @@ test indexObj-8.12 {Tcl_GetIntForIndex end} testgetintforindex { test indexObj-8.13 {Tcl_GetIntForIndex end} testgetintforindex { testgetintforindex end -2 } -2 -test indexObj-8.14 {Tcl_GetIntForIndex end+1} -constraints { - testgetintforindex has64BitLengths -} -body { +test indexObj-8.14 {Tcl_GetIntForIndex end+1} testgetintforindex { testgetintforindex end+1 -1 -} -result 9223372036854775807 -test indexObj-8.14.32bits {Tcl_GetIntForIndex end+1} -constraints { - testgetintforindex has32BitLengths -} -body { - testgetintforindex end+1 -1 -} -result 2147483647 +} [expr {[testConstraint has64BitLengths] ? 9223372036854775807 : 2147483647}] test indexObj-8.15 {Tcl_GetIntForIndex end+1} testgetintforindex { testgetintforindex end+1 -2 } -1 +test indexObj-8.16 {Tcl_GetIntForIndex integer} testgetintforindex { + testgetintforindex -1 -1 +} [expr {[testConstraint has64BitLengths] ? -9223372036854775808 : -2147483648}] +test indexObj-8.17 {Tcl_GetIntForIndex integer} testgetintforindex { + testgetintforindex -2 -1 +} [expr {[testConstraint has64BitLengths] ? -9223372036854775808 : -2147483648}] +test indexObj-8.18 {Tcl_GetIntForIndex n-m} testgetintforindex { + testgetintforindex 2-3 -1 +} [expr {[testConstraint has64BitLengths] ? -9223372036854775808 : -2147483648}] +test indexObj-8.19 {Tcl_GetIntForIndex n-m} testgetintforindex { + testgetintforindex 2-3 0 +} -1 # cleanup ::tcltest::cleanupTests |
