Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#1 An infinite loop can occur in subroutine "quote_highlight"


For some reason, an infinite loop occurs during certain searches. It seems to happen for certain symbols only,
but it happens every time the offending symbol is searched for as long as the type criteria ("symbol", "global",
"called by", "calling", etc.) is the same.

I've found that I can circumvent this infinite loop by adding the variable "failsafe" to the "quote_highlight"
subroutine, and quitting if it gets too big:

proc quote_highlight { widget } {

set pattern {[^\\']\"}

# Look in between commented regions for quotes
foreach {start end} [concat 1.0 [$widget tag ranges comment] end] {

# Do this to avert the "infinite loop bug". 001004 -- jcn
set failsafe 0

while {[set temp [$widget search -regexp -- $pattern $start $end]] != ""} {

# Do this to avert the "infinite loop bug". 001004 -- jcn
set failsafe [expr $failsafe + 1]
if { $failsafe > 1024 } {
puts "Avoided infinite loop in cbrowser!"

set endquote [$widget search -regexp -- {[^\\]\"} "$temp + 1chars" $end]

if {[strlen $endquote] > 0} {
set start [$widget index "$endquote + 2chars"]

$widget tag add quote "$temp + 1chars" $start


  • Charles Slater
    Charles Slater

    Logged In: YES

    Thanks for reporting this bug and fix. I think that this
    infinite loop is very common. People may be browsing a
    mixture of C and python or C files with an error in a quoted
    string statement. The fix is fine. The variable
    "failsafe" could be changed to "lines_in_quote". cbrowser
    can have
    a specified limit of 1024 on the number of line inside a
    highlighted quote.

    There may be better fixes, but this one beats an infinite
    loop. I vote for adding it to the distribution.