diff options
author | Paul Phillips <paulp@improving.org> | 2011-05-29 20:19:55 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-05-29 20:19:55 +0000 |
commit | 1125a9cfab5c5bacfd10bf1a559b97437339dbaf (patch) | |
tree | 5d5155cf1465d1796901773a156d4d9e94efb3b2 /src/compiler/scala/tools/nsc/util/CharArrayReader.scala | |
parent | 75ec2ba72f17a57060ca5831ccc9e38167e957ae (diff) | |
download | scala-1125a9cfab5c5bacfd10bf1a559b97437339dbaf.tar.gz scala-1125a9cfab5c5bacfd10bf1a559b97437339dbaf.tar.bz2 scala-1125a9cfab5c5bacfd10bf1a559b97437339dbaf.zip |
Fixed a crasher in the scanner when unicode esc...
Fixed a crasher in the scanner when unicode escape sequences offered up
EOF before completion. Also made the repl a little more robust against
crashers in scalac. Treat it like a hostile witness! Closes #4584, no
review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/CharArrayReader.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/util/CharArrayReader.scala | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala index c79ac91f49..aee87d8ad9 100644 --- a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala +++ b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala @@ -15,7 +15,7 @@ abstract class CharArrayReader { self => def decodeUni: Boolean = true /** An error routine to call on bad unicode escapes \\uxxxx. */ - protected def error(offset: Int, msg: String) + protected def error(offset: Int, msg: String): Unit /** the last read character */ var ch: Char = _ @@ -68,10 +68,19 @@ abstract class CharArrayReader { self => (charOffset - p) % 2 == 0 } def udigit: Int = { - val d = digit2int(buf(charOffset), 16) - if (d >= 0) charOffset += 1 - else error(charOffset, "error in unicode escape") - d + if (charOffset >= buf.length) { + // Since the positioning code is very insistent about throwing exceptions, + // we have to decrement the position so our error message can be seen, since + // we are one past EOF. This happens with e.g. val x = \ u 1 <EOF> + error(charOffset - 1, "incomplete unicode escape") + SU + } + else { + val d = digit2int(buf(charOffset), 16) + if (d >= 0) charOffset += 1 + else error(charOffset, "error in unicode escape") + d + } } if (charOffset < buf.length && buf(charOffset) == 'u' && decodeUni && evenSlashPrefix) { do charOffset += 1 |