Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2010-02-28
04:25 • Closed ticket [2960021fff]: "string first" command on large string seg... artifact: d00dbf2f3a user: dkf
01:38 • Ticket [2960021fff]: 4 changes artifact: 055c1ce0e8 user: dkf
2010-02-27
14:07 • Ticket [2960021fff]: 4 changes artifact: d1387525b8 user: andreas_kupries
13:51 • Ticket [2960021fff]: 4 changes artifact: 54a0c63044 user: blacksqr
13:50 • Ticket [2960021fff]: 4 changes artifact: e0a73315a2 user: blacksqr
06:47 • New ticket [2960021fff]. artifact: a7e9939e71 user: blacksqr

"string first" command on large string segfaults

Closed / Fixed2960021fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2010-02-27 06:47:17
When the "needleString" argument to a "string first" command is very large, a segmentation fault will result.

It is easy to switch the "needleString" and the "haystackString" by mistake in the "string first" command, and thus encounter this bug.  Mistake notwithstanding, the command is still syntactically correct, and one should expect a "-1" as a return value.

To replicate, simply execute the following procedure:

proc string_first_bug {} {
set line xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
for {set i 0} {$i < 1048547} {incr i} {
append largeString $line\n
}
set line_ [string first $largeString \n]
}

ActiveTcl 8.5.8 on Ubuntu Intrepid.
blacksqrplain2010-02-27 13:50:37
Submit form didn't like tabs in code sample.  Here's an attempt to prettify with spaces:

proc string_first_bug {} {
        set line xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        for {set i 0} {$i < 1048547} {incr i} {
                append largeString $line\n
        }
        set line_ [string first $largeString \n]
}
blacksqrplain2010-02-27 13:51:14
Sourceforge says: no pretty code sample for you!
andreas_kupriesplain2010-02-27 14:07:33
That is why we usually ask to attach code samples and other stuff like that, instead of inlining it into the report or comment.
dkfplain2010-02-28 01:38:17
Weird that it was crashing, but at least we can know when the needle is bigger than the haystack that the former that there is no need to search. Applied those preconditions and the crashes go away.
dkfplain2010-02-28 04:25:43
allow_comments - 1

Fixed in HEAD and 8.5 branch.
Log in (anonymous is fine) to add a comment.