diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-04-29 17:59:40 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-04-29 17:59:40 +0200 |
commit | 02629b84de23bdc5896ac4b357e2f16dfb3996ec (patch) | |
tree | af9dc2ca32f02096966b6fd5b1c25fa594b573fe /lexer.c | |
parent | 2bc9bace716fafa408dfc6683ca3ff0f9d8bc44b (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.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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; } |