From 05a15ffeb366ff68fa35ea7086d4f87684fcafaf Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 16 Feb 2010 17:39:44 -0800 Subject: go/scanner: comply with spec changes (do not allow NUL chars) and complain about illegal UTF-8 code sequences R=rsc CC=golang-dev http://codereview.appspot.com/209043 --- src/pkg/go/scanner/scanner.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/pkg/go/scanner/scanner.go') diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go index 7a21205a9..b2e120179 100644 --- a/src/pkg/go/scanner/scanner.go +++ b/src/pkg/go/scanner/scanner.go @@ -48,12 +48,17 @@ func (S *Scanner) next() { S.pos.Column++ r, w := int(S.src[S.offset]), 1 switch { + case r == 0: + S.error(S.pos, "illegal character NUL") case r == '\n': S.pos.Line++ S.pos.Column = 0 case r >= 0x80: // not ASCII r, w = utf8.DecodeRune(S.src[S.offset:]) + if r == utf8.RuneError && w == 1 { + S.error(S.pos, "illegal UTF-8 encoding") + } } S.offset += w S.ch = r -- cgit v1.2.3