Commit 52f111fb authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: print regular error message in BOM corner-case

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/17047Reviewed-by: 's avatarChris Manghane <cmang@golang.org>
parent 85dcc34e
......@@ -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")
......
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