Skip to content

Commit d6a3f31

Browse files
committed
cgen: protect against unlimited recursion in type_default_impl, by converting to a verror/1 call instead
1 parent 74080e8 commit d6a3f31

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎vlib/v/gen/c/cgen.v‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ mut:
270270
defer_return_tmp_var string
271271
vweb_filter_fn_name string // vweb__filter or x__vweb__filter, used by $vweb.html() for escaping strings in the templates, depending on which `vweb` import is used
272272
export_funcs []string // for .dll export function names
273+
//
274+
type_default_impl_level int
273275
}
274276

275277
@[heap]
@@ -7245,6 +7247,16 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
72457247
}
72467248

72477249
fn (mut g Gen) type_default_impl(typ_ ast.Type, decode_sumtype bool) string {
7250+
g.type_default_impl_level++
7251+
defer {
7252+
g.type_default_impl_level--
7253+
}
7254+
if g.type_default_impl_level > 37 {
7255+
eprintln('>>> Gen.type_default_impl g.type_default_impl_level: ${g.type_default_impl_level} | typ_: ${typ_} | decode_sumtype: ${decode_sumtype}')
7256+
}
7257+
if g.type_default_impl_level > 40 {
7258+
verror('reached maximum levels of nesting for ${@LOCATION}')
7259+
}
72487260
typ := g.unwrap_generic(typ_)
72497261
if typ.has_flag(.option) {
72507262
return '(${g.styp(typ)}){.state=2, .err=_const_none__, .data={E_STRUCT}}'

0 commit comments

Comments
 (0)