Artifacts Associated With Ticket 13d3c0d764fa4cf1
Ticket change [a337784d33] (rid 217204) by apnadkarni on 2023-08-13 15:47:58:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
`lset` is supposed to only allow setting of elements for out of bounds indices when the specified index is just after the last valid index (i.e. equal to list length). However consider ``` % set L {} % lset L 0x7ffffffffffffffe X index "0x7ffffffffffffffe" out of range % lset L 0x7fffffffffffffff X X % lset L 0x7fffffffffffffff X index "0x7fffffffffffffff" out of range ``` When the list is empty, the index 0x7fffffffffffffff (or higher) is incorrectly treated as index 0 (i.e. just beyond last valid index). As the first line shows, smaller out of bounds indices are treated correctly. As the last line shows, this bug only occurs when the list is empty. Like bug [bc076f4f0e](https://core.tcl-lang.org/tcl/tktview/bc076f4f0e), this bug was also introduced by commit [0b05b5c750df](https://core.tcl-lang.org/tcl/info/0b05b5c750df) intended to fix TIP 577 issues in Tk. While this issue may be considered relatively minor, it points to what I think is a fundamental flaw in internal index encoding in Tcl: the number of values that need to be represented in an "index" are greater than the range of the index type, no matter whether 32- or 64-bits. This is due to non-negative integers being valid (for obvious reasons), negative integers being valid (as end-N) representation, which together occupy the entire domain. Then there is a need for additional values representing "end" and "one beyond end" for which there is no room necessitating hacks like [this](https://core.tcl-lang.org/tcl/file?ci=df58824c7868a07c&name=generic/tclListObj.c&ln=2930-2931) which is the cause of the above bug. Removing that hack will cause `lset` to fail on ``` set L {} ; lset L 0 X ``` which should be allowed. Changing the core indexing routines to fix this breaks Tk indexing for negative (in the C API) and end relative indices. Given the above limitation in range of values I see no way around this other than living with the above bug for 9.0. If I am wrong and anyone has a solution, please verify it works with both Tk and the bigdata tests for large indices. - 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: "Minor"
- status initialized to: "Open"
- submitter initialized to: "apnadkarni"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to:
lset on empty list is allowed when index argument is large
- type initialized to: "Bug"
Ticket change [76585c1512] (rid 217370) by jan.nijtmans on 2023-08-25 15:36:40:
- assignee changed to: "jan.nijtmans"
- login: "jan.nijtmans"
- mimetype: "text/plain"
Ticket change [7d81181288] (rid 258956) by serhiy.storchaka on 2026-10-17 16:03:05:
- foundin changed to: "9.0.5, 9.1.0"
- icomment:
The ambiguity can be resolved locally in TclLsetFlat(), without changing the index encoding (so Tk is not affected): when the list is empty and the index comes back as TCL_SIZE_MAX, evaluate it again as if the list had one element, and accept it only if this gives 1 (end+1 and similar forms). Proposed fix in branch [/timeline?r=lset-empty-huge-index|lset-empty-huge-index], tests lset-18.1 to lset-18.5. 8.6 is not affected.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
Ticket change [16102562e1] (rid 261038) by dkf on 2026-11-01 16:58:39:
- closedate changed to: "2461346.2074002433"
- closer changed to: "dkf"
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"