diff options
author | Robert Griesemer <gri@golang.org> | 2010-02-16 17:39:44 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2010-02-16 17:39:44 -0800 |
commit | 05a15ffeb366ff68fa35ea7086d4f87684fcafaf (patch) | |
tree | 2c4061c24cc29a2ed2d1fb664a4abf7f0e2a7ba8 /src/pkg/go/scanner/scanner.go | |
parent | 03e53c11d7001447371b163af4e99f54cd44f194 (diff) | |
download | golang-05a15ffeb366ff68fa35ea7086d4f87684fcafaf.tar.gz |
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
Diffstat (limited to 'src/pkg/go/scanner/scanner.go')
-rw-r--r-- | src/pkg/go/scanner/scanner.go | 5 |
1 files changed, 5 insertions, 0 deletions
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 |