1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:14:40 -07:00

gc: allow colon in //line file name

Assume last colon introduces line number.

Fixes #2543.

R=ken2
CC=golang-dev
https://golang.org/cl/5485047
This commit is contained in:
Russ Cox 2011-12-12 15:41:54 -05:00
parent ebdcbf1cdc
commit ecda0fa5d4

View File

@ -1336,7 +1336,7 @@ static int
getlinepragma(void) getlinepragma(void)
{ {
int i, c, n; int i, c, n;
char *cp, *ep; char *cp, *ep, *linep;
Hist *h; Hist *h;
for(i=0; i<5; i++) { for(i=0; i<5; i++) {
@ -1347,32 +1347,36 @@ getlinepragma(void)
cp = lexbuf; cp = lexbuf;
ep = lexbuf+sizeof(lexbuf)-5; ep = lexbuf+sizeof(lexbuf)-5;
linep = nil;
for(;;) { for(;;) {
c = getr(); c = getr();
if(c == '\n' || c == EOF) if(c == EOF)
goto out; goto out;
if(c == '\n')
break;
if(c == ' ') if(c == ' ')
continue; continue;
if(c == ':') if(c == ':')
break; linep = cp;
if(cp < ep) if(cp < ep)
*cp++ = c; *cp++ = c;
} }
*cp = 0; *cp = 0;
if(linep == nil || linep >= ep)
goto out;
*linep++ = '\0';
n = 0; n = 0;
for(;;) { for(cp=linep; *cp; cp++) {
c = getr(); if(*cp < '0' || *cp > '9')
if(!yy_isdigit(c)) goto out;
break; n = n*10 + *cp - '0';
n = n*10 + (c-'0');
if(n > 1e8) { if(n > 1e8) {
yyerror("line number out of range"); yyerror("line number out of range");
errorexit(); errorexit();
} }
} }
if(n <= 0)
if(c != '\n' || n <= 0)
goto out; goto out;
// try to avoid allocating file name over and over // try to avoid allocating file name over and over