Skip to content
Tcl Source Code View Ticket
Login

View Ticket

lsearch causes segmentation fault

Closed / Fixed694232ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2003-02-27 08:23:43
The command

  lsearch -start 0 {} x

causes a segmentation fault.

This happens in function Tcl_LsearchObjCmd().
The given argument "-start 0" in combination
with an empty list causes the variable "offset"
to become -1.

From snapshot 2003-02-25:

2931         if (offset < 0) {
2932             offset = 0;
2933         } else if (offset > listc-1) {
2934             offset = listc-1;
2935         }

I'd prefer to have line 2934 as follows:

2934             offset = listc > 0 ? listc-1 : 0;

Perhaps this is also worth a test in lsearch.test,
for example:

test lsearch-xx.x {combine -start 0 with empty list} {
    lsearch -start 0 {} x
} -1
dkf Ticket [694232ffff]: 1 change [History diff]2003-02-27 16:50:41
dkfplain2003-02-27 23:14:00
Logged In: YES 
user_id=79902

Fixed.  (Why are these bugs always found during
code-freeze?)
dgpplain2003-02-27 23:55:18
Logged In: YES 
user_id=80530

...because more people actually test
during code freeze?
Log in (anonymous is fine) to add a comment.