]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: print regular error message in BOM corner-case
authorRobert Griesemer <gri@golang.org>
Thu, 19 Nov 2015 01:50:21 +0000 (17:50 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 20 Nov 2015 19:55:15 +0000 (19:55 +0000)
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 <cmang@golang.org>
src/cmd/compile/internal/gc/lex.go

index d6567d0c9cd2e98493582ad0a023e0a548049343..3617493815df9a9a947003122a9942a9568ead54 100644 (file)
@@ -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")