Skip to content
Tcl Source Code View Ticket
Login

View Ticket

dict for {k v} $emptyDict crashes

Closed / Fixed1382528fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-12-16 15:55:16
Test case:
proc bad {} {
    dict for {k v} {} {}
    catch {whoops}
}
bad

causes segfault (linux), access violation (windows).

The crash itself appears in TclStackFree (when
decrementing refcount), but seems to be related with
Tcl_DictObjFirst / Tcl_DictObjDone behavior with empty
values.
dkf Ticket [1382528fff]: 2 changes [History diff]2005-12-16 23:00:14
dkfplain2005-12-16 23:00:15
Logged In: YES 
user_id=79902

Only happens in compiled [dict for].
a_kovalenkoplain2005-12-16 23:48:18
Logged In: YES 
user_id=241496

I know. The problem is in exception ranges: beginCatch
bytecode is not reached with empty dicts, but endCatch is.
a_kovalenkoplain2005-12-16 23:58:54
Logged In: YES 
user_id=241496

The patch solving this problem is attached. beginCatch is
now emitted before the first JumpTrue.
a_kovalenkoplain2005-12-16 23:58:55
File Added - 160100: dict-for.patch
dkfplain2005-12-19 05:42:40
Logged In: YES 
user_id=79902

I'm not going with that because it is likely to inhibit
future bytecode optimizations. Instead, I've split the code
so that the handling of loop-exit is different from the
handling of loop-never-entered. This is a few instructions
longer, but probably faster.

BTW, thanks for spotting that it was a problem with the
management of the catch stack; I was stumped!
Log in (anonymous is fine) to add a comment.

Attachments: