From b2c2c65fbec390c9e5550b0cea6edcaf986ececc Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 21 Feb 2016 15:05:47 -0500 Subject: Fix infinite recursion in eval_not(). And use a helper function to prevent this kind of bug in the future. --- eval.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/eval.c b/eval.c index b5bef33..66ba895 100644 --- a/eval.c +++ b/eval.c @@ -483,33 +483,40 @@ bool eval_xtype(const struct expr *expr, struct eval_state *state) { return false; } +/** + * Evaluate an expression. + */ +static bool eval_expr(const struct expr *expr, struct eval_state *state) { + return expr->eval(expr, state); +} + /** * Evaluate a negation. */ bool eval_not(const struct expr *expr, struct eval_state *state) { - return !expr->rhs->eval(expr, state); + return !eval_expr(expr->rhs, state); } /** * Evaluate a conjunction. */ bool eval_and(const struct expr *expr, struct eval_state *state) { - return expr->lhs->eval(expr->lhs, state) && expr->rhs->eval(expr->rhs, state); + return eval_expr(expr->lhs, state) && eval_expr(expr->rhs, state); } /** * Evaluate a disjunction. */ bool eval_or(const struct expr *expr, struct eval_state *state) { - return expr->lhs->eval(expr->lhs, state) || expr->rhs->eval(expr->rhs, state); + return eval_expr(expr->lhs, state) || eval_expr(expr->rhs, state); } /** * Evaluate the comma operator. */ bool eval_comma(const struct expr *expr, struct eval_state *state) { - expr->lhs->eval(expr->lhs, state); - return expr->rhs->eval(expr->rhs, state); + eval_expr(expr->lhs, state); + return eval_expr(expr->rhs, state); } /** @@ -557,7 +564,7 @@ static enum bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) { if (ftwbuf->visit == expected_visit && ftwbuf->depth >= cmdline->mindepth && ftwbuf->depth <= cmdline->maxdepth) { - cmdline->expr->eval(cmdline->expr, &state); + eval_expr(cmdline->expr, &state); } args->ret = state.ret; -- cgit v1.2.3