mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
scanner: prevent infinite looping, when reaching .eof due to parser bugs
This commit is contained in:
parent
d70cd81875
commit
75b8822f06
@ -44,6 +44,7 @@ pub mut:
|
|||||||
is_fmt bool // Used only for skipping ${} in strings, since we need literal
|
is_fmt bool // Used only for skipping ${} in strings, since we need literal
|
||||||
// string values when generating formatted code.
|
// string values when generating formatted code.
|
||||||
comments_mode CommentsMode
|
comments_mode CommentsMode
|
||||||
|
eofs int
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum CommentsMode {
|
pub enum CommentsMode {
|
||||||
@ -521,8 +522,18 @@ fn (mut s Scanner) skip_whitespace() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (mut s Scanner) end_of_file() token.Token {
|
fn (mut s Scanner) end_of_file() token.Token {
|
||||||
s.pos = s.text.len
|
s.eofs++
|
||||||
|
if s.eofs > 50 {
|
||||||
|
s.line_nr--
|
||||||
|
s.error('the end of file `$s.file_path` has been reached 50 times already, the v parser is probably stuck.\n' +
|
||||||
|
'This should not happen. Please report the bug here, and include the last 2-3 lines of your source code:\n' +
|
||||||
|
'https://github.com/vlang/v/issues/new?labels=Bug&template=bug_report.md'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if s.pos != s.text.len && s.eofs == 1 {
|
||||||
s.inc_line_number()
|
s.inc_line_number()
|
||||||
|
}
|
||||||
|
s.pos = s.text.len
|
||||||
return s.new_token(.eof, '', 1)
|
return s.new_token(.eof, '', 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user