From ecda0fa5d4a448806bdea15e506b11bb71798d8a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 12 Dec 2011 15:41:54 -0500 Subject: [PATCH] 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 --- src/cmd/gc/lex.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c index 4fcf28fe55..af6c207c79 100644 --- a/src/cmd/gc/lex.c +++ b/src/cmd/gc/lex.c @@ -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 -- 2.50.0