Tcl Source Code

View Ticket
Login
2026-10-19
10:13 • Closed ticket [3019348fff]: Nested lset can modify list on error plus 5 othe... artifact: 11a8dab1c2 user: apnadkarni
10:11
Fix [3019348] - Nested lset can modify list on error check-in: 27d3ea715e user: apnadkarni tags: core-9-0-branch
09:58 • Ticket [3019348fff] Nested lset can modify list on error status still Open w... artifact: c82e201be9 user: apnadkarni
09:55
Fix [3019348] - Nested lset can modify list on error check-in: 6a23978bf0 user: apnadkarni tags: trunk, main
06:29 • Ticket [3019348fff] Nested lset can modify list on error status still Open w... artifact: 468e9b0813 user: serhiy.storchaka
04:52 • Ticket [3019348fff]: 3 changes artifact: 74fcf066be user: apnadkarni
2026-10-17
16:54 • Ticket [3019348fff]: 6 changes artifact: c9f0351c63 user: apnadkarni
09:15 • Ticket [3019348fff]: 4 changes artifact: a9f0f9f4fd user: serhiy.storchaka
09:15
Fix [3019348fff]: a nested [lset] which failed after appending an empty sublist for an end+1 index l... closed check-in: c4114a5e1f user: serhiy.storchaka tags: lset-undo-append-on-error
2012-05-30
17:49 • Ticket [3019348fff] Nested lset can modify list on error status still Open w... artifact: f6cc679c34 user: dkf
2010-06-22
14:58 • Ticket [3019348fff]: 2 changes artifact: 2a4855b4aa user: dkf
01:32 • New ticket [3019348fff]. artifact: e487a64ff7 user: andygoth

Ticket UUID: 3019348
Title: Nested lset can modify list on error
Type: Bug Created on: 2010-06-22 01:32:21
Submitter: andygoth Assigned to: apnadkarni
Subsystem: 14. List Object Severity: Minor
Priority: 5 Medium Last modified: 2026-10-19 10:13:36
Status: Closed Closed by: apnadkarni
Resolution: Fixed Closed on: 2026-10-19 10:13:36
Version: 8.6.18, 9.0.5, 9.1.0
Description:
My expectation is that when lset throws an error, it won't modify the list.  However, the following script shows otherwise:

% set foo {}
% lset foo 0 0 x
x
% lset foo 0 1 x
{x x}
% lset foo 1 0 x
{x x} x
% lset foo 1 1 x
{x x} {x x}
% lset foo 2 1 x
list index out of range
% set foo
{x x} {x x} {}
% lset foo 3 0 x
{x x} {x x} {} x
% lset foo 3 1 x
{x x} {x x} {} {x x}

The command [lset foo 2 1 x] throws an error but also adds an empty element to the end of the list.
User Comments:
serhiy.storchaka added on 2026-10-17 09:15:46:

Still present in 8.6, 9.0 and 9.1: since TIP 331 ([41ad4c4b67]) TclLsetFlat() appends an empty sublist for an index equal to the list length before checking the remaining indices, and does not remove it when one of them fails. Inside a procedure the literal list is shared and copied, which hides the problem. Proposed fix in branch lset-undo-append-on-error: remove the appended sublist on error. Tests lset-17.1 to lset-17.3.


apnadkarni added on 2026-10-19 04:52:11:

@serhiy.storchaka Looks fine but I've made some modifications in branch apn-lset-undo-append-on-error to eliminate some redundant/unnecessary checks. If you are ok with those changes, you can commit that branch to trunk and 9.0. Or I can, if you prefer.


serhiy.storchaka added on 2026-10-19 06:29:22:

Your changes look fine to me. The branch conflicted with trunk, where the fix for [526b01c0b9] holds a reference to the sublist around TclListObjSetElement(); I merged trunk into apn-lset-undo-append-on-error and kept that hold in your replace branch (lset-19.1 crashes without it). Please merge it to trunk and 9.0.


apnadkarni added on 2026-10-19 09:58:26:
Fixed for 9.1 in [6a23978bf0]. Pending 9.0 merge.

apnadkarni added on 2026-10-19 10:13:36:

Fixed for 9.0 in [27d3ea715e]. Closing. Thanks!