summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-02-21 15:05:47 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-02-21 15:05:47 -0500
commitb2c2c65fbec390c9e5550b0cea6edcaf986ececc (patch)
tree7fe270fb495e064806999ce605cf3d860a62b839 /eval.c
parent20860becb5a0e89ee2aaaddbb0ba1eb248552640 (diff)
downloadbfs-b2c2c65fbec390c9e5550b0cea6edcaf986ececc.tar.xz
Fix infinite recursion in eval_not().
And use a helper function to prevent this kind of bug in the future.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/eval.c b/eval.c
index b5bef33..66ba895 100644
--- a/eval.c
+++ b/eval.c
@@ -484,32 +484,39 @@ bool eval_xtype(const struct expr *expr, struct eval_state *state) {
}
/**
+ * 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;