summaryrefslogtreecommitdiffhomepage
path: root/lexer.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-04-29 17:59:40 +0200
committerJo-Philipp Wich <jo@mein.io>2021-04-29 17:59:40 +0200
commit02629b84de23bdc5896ac4b357e2f16dfb3996ec (patch)
treeaf9dc2ca32f02096966b6fd5b1c25fa594b573fe /lexer.c
parent2bc9bace716fafa408dfc6683ca3ff0f9d8bc44b (diff)
lexer: fix infinite loop on parsing unterminated comments
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lexer.c')
-rw-r--r--lexer.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lexer.c b/lexer.c
index 616f484..d9d657e 100644
--- a/lexer.c
+++ b/lexer.c
@@ -359,9 +359,6 @@ parse_comment(uc_lexer *lex)
const char *ptr, *end;
size_t elen;
- if (!buf_remaining(lex))
- return emit_op(lex, lex->lastoff, TK_ERROR, ucv_string_new("Unterminated comment"));
-
if (!strcmp(tok->u.pat, "//")) {
end = "\n";
elen = 1;
@@ -381,6 +378,13 @@ parse_comment(uc_lexer *lex)
buf_consume(lex, ptr - lex->bufstart);
+ if (lex->eof) {
+ lex->state = UT_LEX_EOF;
+
+ if (elen == 2)
+ return emit_op(lex, lex->lastoff, TK_ERROR, ucv_string_new("Unterminated comment"));
+ }
+
return NULL;
}