parser: add hard limit to the number of statements in a fn
parent
8dcc3cda97
commit
c6ae322f85
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue