go/scanner: don't allow "0x" and "0X" as integers

R=gri
CC=golang-dev
https://golang.org/cl/4560047
This commit is contained in:
Evan Shaw 2011-05-27 16:47:26 -07:00 committed by Robert Griesemer
parent 399a311e64
commit f369fc09f4
2 changed files with 6 additions and 0 deletions

View File

@ -297,6 +297,10 @@ func (S *Scanner) scanNumber(seenDecimalPoint bool) token.Token {
// hexadecimal int
S.next()
S.scanMantissa(16)
if S.offset-offs <= 2 {
// only scanned "0x" or "0X"
S.error(offs, "illegal hexadecimal number")
}
} else {
// octal int or float
seenDecimalDigit := false

View File

@ -672,6 +672,8 @@ var errors = []struct {
{"078e0", token.FLOAT, 0, ""},
{"078", token.INT, 0, "illegal octal number"},
{"07800000009", token.INT, 0, "illegal octal number"},
{"0x", token.INT, 0, "illegal hexadecimal number"},
{"0X", token.INT, 0, "illegal hexadecimal number"},
{"\"abc\x00def\"", token.STRING, 4, "illegal character NUL"},
{"\"abc\x80def\"", token.STRING, 4, "illegal UTF-8 encoding"},
}