Commit f369fc09 authored by Evan Shaw's avatar Evan Shaw Committed by Robert Griesemer

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

R=gri
CC=golang-dev
https://golang.org/cl/4560047
parent 399a311e
......@@ -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
......
......@@ -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"},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment