Commit d749783f authored by Russ Cox's avatar Russ Cox

cmd/gc: skip over reported BOMs

This keeps the BOM runes from causing other errors.

R=golang-dev, remyoudompheng
CC=golang-dev
https://golang.org/cl/6625062
parent 65b782e9
...@@ -1532,7 +1532,7 @@ yylex(void) ...@@ -1532,7 +1532,7 @@ yylex(void)
static int static int
getc(void) getc(void)
{ {
int c; int c, c1, c2;
c = curio.peekc; c = curio.peekc;
if(c != 0) { if(c != 0) {
...@@ -1545,8 +1545,20 @@ getc(void) ...@@ -1545,8 +1545,20 @@ getc(void)
c = *curio.cp & 0xff; c = *curio.cp & 0xff;
if(c != 0) if(c != 0)
curio.cp++; curio.cp++;
} else } else {
loop:
c = Bgetc(curio.bin); c = Bgetc(curio.bin);
if(c == 0xef) {
c1 = Bgetc(curio.bin);
c2 = Bgetc(curio.bin);
if(c1 == 0xbb && c2 == 0xbf) {
yyerrorl(lexlineno, "Unicode (UTF-8) BOM in middle of file");
goto loop;
}
Bungetc(curio.bin);
Bungetc(curio.bin);
}
}
check: check:
switch(c) { switch(c) {
...@@ -1597,10 +1609,6 @@ loop: ...@@ -1597,10 +1609,6 @@ loop:
if(!fullrune(str, i)) if(!fullrune(str, i))
goto loop; goto loop;
c = chartorune(&rune, str); c = chartorune(&rune, str);
if(rune == BOM) {
lineno = lexlineno;
yyerror("Unicode (UTF-8) BOM in middle of file");
}
if(rune == Runeerror && c == 1) { if(rune == Runeerror && c == 1) {
lineno = lexlineno; lineno = lexlineno;
yyerror("illegal UTF-8 sequence"); yyerror("illegal UTF-8 sequence");
......
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