Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[lindex] accepts bad index

Closed / Fixed1718580fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 19 years ago
Descriptionplain2007-05-14 12:21:25
Mistyping [lindex] where I meant [linsert], I discovered the following behaviour:  [lindex {} end foo] does not throw an error, whereas [lindex {} foo] does! Or as an example session:

% info patchlevel
8.5a6
% lindex {} foo
bad index "foo": must be integer?[+-]integer? or end?[+-]integer?
% lindex {} end foo
% lindex a end foo
bad index "foo": must be integer?[+-]integer? or end?[+-]integer?
% lindex {} 0 foo
% lindex {} -1 foo
% lindex {} foo foo
bad index "foo": must be integer?[+-]integer? or end?[+-]integer?

This is probably due to lines 1108-1115 of tclListObj.c (v 1.46): once an out-of-bounds index is encountered, remaining indices are ignored. Indeed,

% lindex a 1 foo
% lindex a 0 foo
bad index "foo": must be integer?[+-]integer? or end?[+-]integer?
% lindex a -1 foo
dkf Ticket [1718580fff]: 2 changes [History diff]2007-05-14 19:37:18
dgp Ticket [1718580fff]: 1 change [History diff]2007-05-14 21:31:16
kennykb Closed ticket [1718580fff]. [History diff]2007-09-04 04:28:13
Log in (anonymous is fine) to add a comment.