Aladdin - Scala Bugtracking
[#1180] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Nikolay Lex fixed 2007-06-17 19:01:10.0
subject [contrib #653] scanner can fall to endless loop
code
in CharArrayReader.scala:53

  def next: Char = {
    //cline = nextline
    //ccol = nextcol
    if(!hasNext) 
      return SU  // there is an endless stream of SU's at the end 
    oldBp = bp
    oldCh = ch;
    ch = buf(bp)

in Scanners.scala:395
    private def fetchToken(): unit = {
      if (token == EOF) return
      lastPos = in.cpos - 1 // Position.encode(in.cline, in.ccol)
      //var index = bp
      while (true) {
        in.ch match {
          case ' ' | '\t' | CR | LF | FF =>
            in.next
what happened
when called nextToken at end of file, endless loop begins in fetchToken. This is due of in.ch not updated and un\
conditional while(true) loop executed. token never set to EOF due of SU (SU never assigned to in.ch)
what expected chararray should set ch to SU and optionally while(true) should be replaced while(in.hasNext) minimal fix: def next: Char = { //cline = nextline //ccol = nextcol if(!hasNext) { ch = SU return SU // there is an endless stream of SU's at the end }
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-06-17 19:02:33.0
I'm confused. Is this really a bug? What input can trigger it?
Stephane  edited on  2007-06-26 14:57:50.0
reassigned to Lex
Lex  edited on  2007-07-13 21:26:05.0
I agree about setting ch to SU, and have changed it. I disagree about changing the while(true), because the handling for the case of !in.hasNext is already included inside the loop.