diff options
| author | Toby Goodwin <toby@nqmail.org> | 2018-05-30 22:46:38 +0100 |
|---|---|---|
| committer | Toby Goodwin <toby@nqmail.org> | 2018-05-30 22:46:38 +0100 |
| commit | 9d071b26bf1b1dcd71efb06dc4fb6c25803856a0 (patch) | |
| tree | 9a5a94477fc6034977cb6f3ee20ad927409c9867 | |
| parent | dc29bf28ac586e9790f0784785774589fb367c9b (diff) | |
if_state was being clobbered while running body of succeeding if
| -rw-r--r-- | walk.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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) |