parser: add hard limit to the number of statements in a fn

pull/6043/head
Delyan Angelov 2020-08-02 17:58:05 +03:00
parent 8dcc3cda97
commit c6ae322f85
1 changed files with 9 additions and 0 deletions

View File

@ -321,12 +321,21 @@ pub fn (mut p Parser) parse_block_no_scope(is_top_level bool) []ast.Stmt {
p.check(.lcbr)
mut stmts := []ast.Stmt{}
if p.tok.kind != .rcbr {
mut c := 0
for {
stmts << p.stmt(is_top_level)
// p.warn('after stmt(): tok=$p.tok.str()')
if p.tok.kind in [.eof, .rcbr] {
break
}
c++
if c % 100000 == 0 {
eprintln('parsed $c statements so far from fn $p.cur_fn_name ...')
}
if c > 1000000 {
p.error_with_pos('parsed over $c statements from fn $p.cur_fn_name, the parser is probably stuck',
p.tok.position())
}
}
}
if is_top_level {