From: Robert Griesemer Date: Thu, 19 Nov 2015 01:50:21 +0000 (-0800) Subject: cmd/compile: print regular error message in BOM corner-case X-Git-Tag: go1.6beta1~349 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=52f111fb34a4f57404db53af4d89d4a25fcb114e;p=gostls13.git 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/17047 Reviewed-by: Chris Manghane --- diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go index d6567d0c9c..3617493815 100644 --- a/src/cmd/compile/internal/gc/lex.go +++ b/src/cmd/compile/internal/gc/lex.go @@ -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")