aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2012-08-15 11:09:34 -0700
committerRobert Griesemer <gri@golang.org>2012-08-15 11:09:34 -0700
commitace14d01bda6f8384dea8ab7307e657d80471054 (patch)
tree784df17a412e1e6491052c0d7612e07b30b61fdf /src/pkg/text
parent2ab18f69a6eb76951f5e06bf6e291cdd56a827b4 (diff)
downloadgo-ace14d01bda6f8384dea8ab7307e657d80471054.tar.xz
text/scanner: report illegal hexadecimal numbers (bug fix)
R=r CC=golang-dev https://golang.org/cl/6450136
Diffstat (limited to 'src/pkg/text')
-rw-r--r--src/pkg/text/scanner/scanner.go11
-rw-r--r--src/pkg/text/scanner/scanner_test.go3
2 files changed, 11 insertions, 3 deletions
diff --git a/src/pkg/text/scanner/scanner.go b/src/pkg/text/scanner/scanner.go
index 565650edf9..6492d322f8 100644
--- a/src/pkg/text/scanner/scanner.go
+++ b/src/pkg/text/scanner/scanner.go
@@ -389,15 +389,20 @@ func (s *Scanner) scanNumber(ch rune) (rune, rune) {
if ch == 'x' || ch == 'X' {
// hexadecimal int
ch = s.next()
+ hasMantissa := false
for digitVal(ch) < 16 {
ch = s.next()
+ hasMantissa = true
+ }
+ if !hasMantissa {
+ s.error("illegal hexadecimal number")
}
} else {
// octal int or float
- seenDecimalDigit := false
+ has8or9 := false
for isDecimal(ch) {
if ch > '7' {
- seenDecimalDigit = true
+ has8or9 = true
}
ch = s.next()
}
@@ -408,7 +413,7 @@ func (s *Scanner) scanNumber(ch rune) (rune, rune) {
return Float, ch
}
// octal int
- if seenDecimalDigit {
+ if has8or9 {
s.error("illegal octal number")
}
}
diff --git a/src/pkg/text/scanner/scanner_test.go b/src/pkg/text/scanner/scanner_test.go
index bb3adb55a7..be3998a35a 100644
--- a/src/pkg/text/scanner/scanner_test.go
+++ b/src/pkg/text/scanner/scanner_test.go
@@ -446,6 +446,9 @@ func TestError(t *testing.T) {
testError(t, `"\'"`, "1:3", "illegal char escape", String)
testError(t, `01238`, "1:6", "illegal octal number", Int)
+ testError(t, `01238123`, "1:9", "illegal octal number", Int)
+ testError(t, `0x`, "1:3", "illegal hexadecimal number", Int)
+ testError(t, `0xg`, "1:3", "illegal hexadecimal number", Int)
testError(t, `'aa'`, "1:4", "illegal char literal", Char)
testError(t, `'`, "1:2", "literal not terminated", Char)