Artifacts Associated With Ticket fa00fbbbabe2d779
Ticket change [d315be1fe1] (rid 212643) by apnadkarni on 2023-04-12 14:31:09:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
I expect lindex with indices larger than list size to return empty string. This is the case with small lseq ranges but not large ones (64-bit build) ``` % lindex [lseq 0x10] 0x11 -> correctly returns empty string % lindex [lseq 0x7fffffff] 0x80000000 -> generates error instead index 2147483648 is out of bounds 0 to 2147483646 % ``` Another possibly related (on 32-bit build) ``` % lindex [lseq 0xffffffff] 0x80000000 -> should return 2147483648 % ``` This last may be related to signed/unsigned indexing and may go away with TIP 660. Finally, some check (and exception) is needed when list limit is exceeded. The following on *32-bit* Tcl should generate an error since the full range of elements cannot be accessed by indexing. ``` % llength [lseq 0x100000000] 0 ``` I have not tried this on the tip-636 branch. /Ashok
- foundin initialized to: "9.0"
- is_private initialized to: "0"
- login: "apnadkarni"
- priority initialized to: "5 Medium"
- private_contact initialized to: "9546e9877f1a8899e25a89082561ee694e7fb402"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "apnadkarni"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to: "lseq / lindex discrepancies"
- type initialized to: "Bug"
Ticket change [c37e20118a] (rid 212647) by apnadkarni on 2023-04-12 15:33:52:
- comment changed to:
I expect lindex with indices larger than list size to return empty string. This is the case with small lseq ranges but not large ones (64-bit build) ``` % lindex [lseq 0x10] 0x11 -> correctly returns empty string % lindex [lseq 0x7fffffff] 0x80000000 -> generates error instead index 2147483648 is out of bounds 0 to 2147483646 % ``` Another possibly related (on 32-bit build). This may be related to signed/unsigned indexing and may go away with TIP 660. ``` % lindex [lseq 0xffffffff] 0x80000000 -> should return 2147483648 % ``` Finally, some check (and exception) is needed when list limit is exceeded. The following on *32-bit* Tcl should generate an error since the full range of elements cannot be accessed by indexing. ``` % llength [lseq 0x100000000] 0 ``` I have not tried this on the tip-636 branch. /Ashok
- login: "apnadkarni"
- mimetype: "text/plain"
- comment changed to:
Ticket change [301d94bd2c] (rid 212750) by apnadkarni on 2023-04-14 02:54:19:
- icomment:
The equivalent on 64 bit builds also fails. ``` % set l [lseq 0x7fffffffffffffff]; llength $l 9223372036854775807 % lindex $l 9223372036854775800 -> returns empty string % ``` Again, I'm not sure if this is a Tcl index implementation issue or lseq since it is not possible to test equivalent in "traditional" lists that cannot reach that size.
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [b5b7d0c2b6] (rid 212751) by apnadkarni on 2023-04-14 02:54:56:
- login: "apnadkarni"
- mimetype: "text/plain"
Ticket change [a08d9bf350] (rid 212752) by apnadkarni on 2023-04-14 03:01:47:
- icomment:
There is also a difference between the compiled and uncompiled results, neither of which is the correct result: ``` % set l [lseq 0x7fffffffffffffff]; llength $l 9223372036854775807 % lindex $l 9223372036854775800 % set lindex lindex lindex % $lindex $l 9223372036854775800 -9223372036854775808% set l [lseq 0x7fffffffffffffff]; llength $l 9223372036854775807 % lindex $l 9223372036854775800 % set lindex lindex lindex % $lindex $l 9223372036854775800 -9223372036854775808 ```
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [901c1085fd] (rid 213108) by griffin on 2023-04-16 23:02:10:
- icomment:
The last issue is a general problem with byte compiler and index values. This comment from tclUtil.c explains: * TclIndexEncode -- * * Parse objPtr to determine if it is an index value. Two cases * are possible. The value objPtr might be parsed as an absolute * index value in the C signed int range. Note that this includes * index values that are integers as presented and it includes index * arithmetic expressions. The absolute index values that can be * directly meaningful as an index into either a list or a string are * those integer values >= TCL_INDEX_START (0) * and < INT_MAX. * The largest string supported in Tcl 8 has bytelength INT_MAX. * This means the largest supported character length is also INT_MAX, * and the index of the last character in a string of length INT_MAX * is INT_MAX-1. It looks like this was missed when moving from 32-bit indices to 64-bit indices.
- login: "griffin"
- mimetype: "text/plain"
- icomment:
Ticket change [04fcc06f03] (rid 213118) by apnadkarni on 2023-04-17 01:59:33:
- icomment:
I don't think that TclIndexEncode was missed in moving to 64-bits but rather it was intentional. Iirc, the byte code format is limited to 32-bits and the TclIndexEncode/TclIndexDecode are only used for immediate literal operands (N or end-N) in that range. Operands in variables or outside that range use the TclGetIntForIndexM (or its function equivalent) and load the value from Tcl_Objs on the stack. That is my understanding. Having said that, there is a ticket logged for some index values so there are definitely some issues that need to be resolved in that area.
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [b45c490cfb] (rid 213119) by griffin on 2023-04-17 03:10:31:
- icomment:
Ok then. I will fix the compilation to detect overflow for literals and take appropriate measures. Thanks!
- login: "griffin"
- mimetype: "text/plain"
- icomment:
Ticket change [b57b6950c2] (rid 213514) by griffin on 2023-04-21 15:44:23:
- assignee changed to: "griffin"
- login: "griffin"
- mimetype: "text/plain"
Ticket change [fb5d0ecad2] (rid 213918) by griffin on 2023-04-26 16:29:15:
- closedate changed to: "2460061.18698139"
- closer changed to: "griffin"
- icomment: "Fixed with check-in [a610e50b2faa8c52]"
- login: "griffin"
- mimetype: "text/x-fossil-plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"