From 9d071b26bf1b1dcd71efb06dc4fb6c25803856a0 Mon Sep 17 00:00:00 2001 From: Toby Goodwin Date: Wed, 30 May 2018 22:46:38 +0100 Subject: if_state was being clobbered while running body of succeeding if --- walk.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'walk.c') diff --git a/walk.c b/walk.c index 3032a37..32ca440 100644 --- a/walk.c +++ b/walk.c @@ -19,6 +19,7 @@ static bool dofork(bool); static void dopipe(Node *); static void loop_body(Node* n); static int if_state = 2; /* last if, for "if not" interactive top-level */ +static int old_if_state = 2; /* Tail-recursive version of walk() */ @@ -34,7 +35,7 @@ top: sigchk(); set(TRUE); return TRUE; } - if (parent && n->type != nIfnot) if_state = 2; + if ((n->type != nIf) && (n->type != nIfnot)) if_state = 2; switch (n->type) { case nArgs: case nBackq: case nConcat: case nCount: case nFlat: case nLappend: case nRedir: case nVar: @@ -100,7 +101,10 @@ top: sigchk(); cond = TRUE; if_state = walk(n->u[0].p, TRUE); cond = oldcond; - WALK(if_state ? true_cmd : false_cmd, parent); + old_if_state = if_state; + walk(if_state ? true_cmd : false_cmd, parent); + if_state = old_if_state; + break; } case nIfnot: { if (if_state == 2) -- cgit v1.2.3