]> Cypherpunks repositories - gostls13.git/commitdiff
gc: allow colon in //line file name
authorRuss Cox <rsc@golang.org>
Mon, 12 Dec 2011 20:41:54 +0000 (15:41 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 12 Dec 2011 20:41:54 +0000 (15:41 -0500)
Assume last colon introduces line number.

Fixes #2543.

R=ken2
CC=golang-dev
https://golang.org/cl/5485047

src/cmd/gc/lex.c

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