diff --git a/src/bif_functions.c b/src/bif_functions.c index 2f006f4c..c8e98ef8 100644 --- a/src/bif_functions.c +++ b/src/bif_functions.c @@ -275,6 +275,8 @@ bool call_builtin(query *q, cell *c, pl_idx c_ctx) #endif if (!c->bif_ptr->evaluable && (c->val_off != g_float_s)) return throw_error(q, &q->accum, q->st.curr_frame, "type_error", "evaluable"); + else if (q->max_eval_depth++ > g_max_depth) + return throw_error(q, q->st.curr_instr, q->st.curr_frame, "type_error", "evaluable"); else c->bif_ptr->fn(q); @@ -297,6 +299,7 @@ static bool bif_iso_is_2(query *q) { GET_FIRST_ARG(p1,any); GET_NEXT_ARG(p2_tmp,any); + q->max_eval_depth = 0; CLEANUP cell p2 = eval(q, p2_tmp); p2.nbr_cells = 1; diff --git a/src/internal.h b/src/internal.h index e6378d84..38dfe0f8 100644 --- a/src/internal.h +++ b/src/internal.h @@ -693,7 +693,7 @@ struct query_ { uint64_t tot_tcos, step, qid, tmo_msecs, chgen, cycle_error; uint64_t get_started, autofail_n, yield_at; uint64_t cpu_started, time_cpu_last_started, future; - unsigned max_depth, print_idx, tab_idx, dump_var_nbr; + unsigned max_depth, max_eval_depth, print_idx, tab_idx, dump_var_nbr; unsigned varno, tab0_varno, curr_engine, curr_chan, my_chan, oom; unsigned s_cnt; pl_idx tmphp, latest_ctx, popp, variable_names_ctx;