Tk Library Source Code

View Ticket
Login
Ticket UUID: 3593689
Title: Busyloop in [struct::list nextperm]
Type: Bug Version: None
Submitter: dkf Created on: 2012-12-07 14:21:48
Subsystem: struct :: list Assigned To: andreas_kupries
Priority: 9 Immediate Severity:
Status: Closed Last Modified: 2012-12-08 03:35:32
Resolution: Fixed Closed By: andreas_kupries
    Closed on: 2012-12-07 20:35:32
Description:
If you do:

   package require struct::list 1.8.1
   struct::list nextperm {1 10 9 8 7 6 5 4 3 2}

You get a script that takes an excessively long time to respond (and that will eventually produce a weird error; might take a *long* time!). The problem is that there is a loop that has the wrong condition, using '>=' as an ordering relation directly on values (that happen to be numeric) rather than using [string compare] to do the comparison.

Change:

    while { $aj >= [set al [lindex $perm $l]] } {

to:

    while { [string compare $aj [set al [lindex $perm $l]]] >= 0 } {

This will fix the problem by making string comparison be used throughout.
User Comments: andreas_kupries added on 2012-12-08 03:35:32:

allow_comments - 1

Applied the patch, extended testsuite. Bumped version to 1.8.2.
Committed. Pushed. (Fossil repository setup working).