X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=lex.c;h=ae73dc1f97ac26b527b8de9bed40455f7a5620f3;hb=d5dcb3aff72f4411c83ce97eb13006931fc186f6;hp=7b55dff5033269203a3893804f7a61c89e64b468;hpb=da802480168d2198d356836348b4e5a4ce31a1c9;p=xonotic%2Fgmqcc.git diff --git a/lex.c b/lex.c index 7b55dff..ae73dc1 100644 --- a/lex.c +++ b/lex.c @@ -39,16 +39,17 @@ static const char *const lex_keywords[] = { struct lex_file *lex_open(FILE *fp) { struct lex_file *lex = mem_a(sizeof(struct lex_file)); - if (lex) { - lex->file = fp; - fseek(lex->file, 0, SEEK_END); - lex->length = ftell(lex->file); - lex->size = lex->length; /* copy, this is never changed */ - fseek(lex->file, 0, SEEK_SET); - lex->last = 0; + if (!lex || !fp) + return NULL; - memset(lex->peek, 0, sizeof(lex->peek)); - } + lex->file = fp; + fseek(lex->file, 0, SEEK_END); + lex->length = ftell(lex->file); + lex->size = lex->length; /* copy, this is never changed */ + fseek(lex->file, 0, SEEK_SET); + lex->last = 0; + + memset(lex->peek, 0, sizeof(lex->peek)); return lex; } @@ -236,7 +237,7 @@ static int lex_skipcmt(struct lex_file *file) { lex_addch(ch, file); while ((ch = lex_getch(file)) != '*') { if (ch == EOF) - return error(ERROR_LEX, "malformatted comment at line %d", file->line); + return error(ERROR_LEX, "malformatted comment at line", ""); else lex_addch(ch, file); }