Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2008-01-23
00:00 • Ticket [1876793fff] lreverse crashes on unshared empty list status still Clo... artifact: c09203ae2e user: dgp
2008-01-22
20:20 • Ticket [1876793fff]: 4 changes artifact: 67d6b858bb user: msofer
18:41 • Closed ticket [1876793fff]. artifact: 93765541ad user: msofer
18:16 • Ticket [1876793fff]: 4 changes artifact: 1e800b63e5 user: msofer
06:24 • Ticket [1876793fff]: 2 changes artifact: c54f34b78b user: hobbs
05:40 • Ticket [1876793fff]: 4 changes artifact: 8af5a4d7eb user: tallniel
05:34 • Ticket [1876793fff]: 1 change artifact: 0a8b658a75 user: tallniel
05:34 • Ticket [1876793fff]: 1 change artifact: c60a8ebc57 user: tallniel
05:33 • Ticket [1876793fff]: 4 changes artifact: e0c6c22f4c user: tallniel
2008-01-21
22:18 • New ticket [1876793fff]. artifact: 64f0c98fb5 user: tallniel

lreverse crashes on unshared empty list

Closed / Fixed1876793fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 19 years ago
Descriptionplain2008-01-21 22:18:35
I am seeing a bus error on Mac OS X 10.4.11 (Intel) using current Tcl CVS HEAD. A minimal script to reproduce the crash is the following:

proc foo args {
    set n [lrange $args 0 end]
    lreverse [lrange $n 0 end-1]
}
foo bar

I'm not entirely sure where the problem lies, but it seems to be some combination of the use of "args", the 2 uses of "lrange", and it seems to rely on the "end-N" syntax (just "lrange $n 0 end" doesn't cause a bus error). I suspect a tricky ref-counting bug somewhere and am investigating further. I'll add more here if I track it down.

Neil
tallnielplain2008-01-22 05:33:21
Logged In: YES 
user_id=102050
Originator: YES

gdb isn't showing much interesting as is typical with ref-counting bugs: the location of the error is well removed from where the memory violation shows up. An even more minimal script is:

lreverse [lrange [lrange foo 0 end] 0 end-1]
or
lreverse [lrange [lrange foo 0 end-1] 0 end]

Both lreverse and the end-1 syntax seem to be needed, but "args" is a red herring.
tallniel Ticket [1876793fff]: 1 change [History diff]2008-01-22 05:34:15
tallniel Ticket [1876793fff]: 1 change [History diff]2008-01-22 05:34:29
tallnielplain2008-01-22 05:40:53
Logged In: YES 
user_id=102050
Originator: YES

Gah, tracking it down even further, this could be a problem with shared literals for empty lists. The following also causes a bus error:
lreverse [lrange [lrange {} 0 -1] 0 0]
and the even the following:
lreverse [lrange {} 0 -1]
causes a bus error if it is the first use of an empty list in the program, but if you do say:
set a {}
lreverse [lrange {} 0 -1]
then there is no crash.
hobbs Ticket [1876793fff]: 2 changes [History diff]2008-01-22 06:24:27
msoferplain2008-01-22 18:16:17
Logged In: YES 
user_id=148712
Originator: NO

Even simpler:
mig@uh:~$ /home/CVS/tcl_SF_clean/unix/tclsh
% lreverse {}
Segmentation fault
msofer Closed ticket [1876793fff]. [History diff]2008-01-22 18:41:06
msoferplain2008-01-22 20:20:55
Logged In: YES 
user_id=148712
Originator: NO

This was a bug in bugfix #1672585
dgpplain2008-01-23 00:00:26
Logged In: YES 
user_id=80530
Originator: NO


I dispute that; but happy to
see the fix anyway. :)
Log in (anonymous is fine) to add a comment.