Tk Library Source Code

View Ticket
Bounty program for improvements to Tcl and certain Tcl packages.
Ticket UUID: 984407
Title: Hang in ctext with regexp match
Type: Bug Version: None
Submitter: tallniel Created on: 2004-07-03 00:11:32
Subsystem: tklib :: ctext Assigned To: georgeps
Priority: 5 Medium Severity:
Status: Open Last Modified: 2004-07-06 06:13:38
Resolution: None Closed By:
    Closed on:
Just been playing with ctext and I ran into a bug which causes an 
endless loop on my system. The problem came from trying to 
highlight Tcl comments, using:

ctext::addHighlightClassForRegexp $win comment navy 

Then if I add the following to the text widget:

This is a test
# This is a test

Then position the cursor somewhere in the comment, and press 
backspace - endless loop occurs in ctext::highlight - the third while 
1 loop. Problem seems to be that the [$win search..] stuff is 
passed indices like 4.0 3.15  (i.e. start is after end), and it return 
3.0 bizarrely (this may be a bug in the text widget, or possibly in 
the Mac OS X implementation - I haven't followed up yet). The fix 
was to add these lines after the {"" == $res} check:

# If result given is less than the start index (can happen), then
# break out
foreach {l1 c1} [split $res .] {l2 c2} [split $si .] { break }
if {$l1 < $l2 || ($l1 == $l2 && $c1 < $c2)} { break }

Everything seems to work again after adding that in. I would 
upload a patch, but I'm very busy at present. Hassle me by email 
if you really really want a patch!
User Comments: georgeps added on 2004-07-06 06:13:38:
Logged In: YES 

This failure only occurs with Tk 8.5/HEAD.  I can't
duplicate it with 8.4.6.

With 8.4.6 this *does not* work:
ctext::addHighlightClassForRegexp .ct comment navy {#[^\n]*\n}
That same RE works properly in 8.5/HEAD.

This RE always seems to work (and interestingly seems to
avoid the endless loop with 8.5):
ctext::addHighlightClassForRegexp .ct comment khaki {#[^\n\r]*}

Time to file a bug for Tk I think.