Skip to content

Commit

Permalink
cmd/compile: print regular error message in BOM corner-case
Browse files Browse the repository at this point in the history
This never happens but for pathological input where a BOM sequence
is unfinished and ends in EOF (src: "package p\n\nfunc \xef\xef").
No test case added because the /test framework doesn't lend itself
easily to it in this case (file must end in EOF rather than comment).
Instead, tested manually.

Fixes #13268.

Change-Id: I049034e6dde7ad884b0a8c329921adac1866ff18
Reviewed-on: https://go-review.googlesource.com/17047
Reviewed-by: Chris Manghane <[email protected]>
  • Loading branch information
griesemer committed Nov 20, 2015
1 parent 85dcc34 commit 52f111f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cmd/compile/internal/gc/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -2001,10 +2001,12 @@ func getc() int {
} else {
loop:
c = obj.Bgetc(curio.bin)
// recognize BOM (U+FEFF): UTF-8 encoding is 0xef 0xbb 0xbf
if c == 0xef {
buf, err := curio.bin.Peek(2)
if err != nil {
log.Fatalf("getc: peeking: %v", err)
yyerrorl(int(lexlineno), "illegal UTF-8 sequence ef % x followed by read error (%v)", string(buf), err)
errorexit()
}
if buf[0] == 0xbb && buf[1] == 0xbf {
yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file")
Expand Down

0 comments on commit 52f111f

Please sign in to comment.