Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ecd56ab4d3f2fba808f5a56df90017f554c59e2a
Ticket: 219073ffffffffffffffffffffffffffffffffff
[regexp -all {a*} a] loops infinitely
User & Date: nobody on 2000-10-26 01:10:19
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 4981 Bug
    Version: 8.3
    SubmitDate: '2000-04-10'
    LastModified: '2000-04-10'
    Severity: CRIT
    Status: Released
    Submitter: ericm
    ChangedBy: ericm
    OS: All
    FixedDate: '2000-04-10'
    FixedInVersion: 8.3.1
    ClosedDate: '2000-10-25'
    
    
    Because of the implementation of regexp -all, this command:
    
    regexp -all {a*} a
    
    will loop indefinately.  The problem is traced to the regexp command, in which the following (essentially) occurs:
    
    while (1) {
    matchRegexp(...offset...);
    
    ...
    
    offset += matchLength;
    }
    
    In the case of {a*} and the string a, the regexp will match the {} at the end of the string.  Of course, the length of {} is 0, so the offset never gets incremented, so the next pass through the loop matches against the same chunk of the string.  And so on, ad infinitum.
    
    The fix requires two changes:
    
    1.  offset should always be incremented by min(1, matchLength)
    2.  after offset has been incremented, it should be tested to see if it is past the end of the string; if so, the loop should terminate.  the regexp matching engine has the invarient that starting indices past the end of the string get confined to the range of the string, so specifying an offset of stringLength+1 will not cause it to fail to match -- it will just interpret that as stringLength.
    
    - eric
    
    
    
    Fixed for 8.3.1., with tests.
    
    - eric
    
    
  4. foundin changed to: "obsolete: 8.3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "43. Regexp"
  10. title changed to: "[regexp -all {a*} a] loops infinitely"
  11. type changed to: "Bug"