scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit afa1694d36865e5f2d5858e641c573502edaef92
parent dbb2ca15669b9542a46f2232ce74c3f95afd2902
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 18 Jul 2015 09:08:28 +0200

Fix #line

The validation of the fields in #line were incorrect, and the last
token was not consumed, generating an error in cpp() due to garbage
at the end of the line.

Diffstat:
cc1/cpp.c | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -409,15 +409,14 @@ too_long: static void line(void) { - Type *tp; long n; + char *endp; if (cppoff) return; - if ((n = strtol(input->p, &input->p, 10)) <= 0 || n > USHRT_MAX) - error("first parameter of #line is not a positive integer"); - if (yytoken != CONSTANT || yylval.sym->type != inttype) + n = strtol(yytext, &endp, 10); + if (n <= 0 || n > USHRT_MAX || *endp != '\0') error("first parameter of #line is not a positive integer"); input->nline = yylval.sym->u.i; @@ -425,11 +424,11 @@ line(void) if (yytoken == EOFTOK) return; - tp = yylval.sym->type; - if (yytoken != CONSTANT || tp->op != ARY && tp->type != chartype) + if (*yytext != '\"'|| yylen == 1) error("second parameter of #line is not a valid filename"); free(input->fname); input->fname = xstrdup(yylval.sym->u.s); + next(); } static void