From 41b50445eab2eb71c4446f85e368a273b52c39a3 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 17 Sep 2002 10:42:17 +0000 Subject: 17673: Fix bug with &&s and ||s in complex constructs --- ChangeLog | 7 +++++++ Src/exec.c | 18 ++++++++++++++++-- Test/A01grammar.ztst | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae372dfab..1ebae4faa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-09-17 Peter Stephenson + + * 17673: Src/exec.c, Test/A01grammar.ztst: + for X in Y; true || B; done && X + executed X on every iteration. Same bug with true -> false, + || -> &&, && -> ||. + 2002-09-16 Oliver Kiddle * 17678: Src/builtin.c: ignore initial `--' argument to printf diff --git a/Src/exec.c b/Src/exec.c index 9033e146d..ca7b2061f 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -851,8 +851,15 @@ execlist(Estate state, int dont_change_job, int exiting) * for this sublist. */ donetrap = 1; goto sublist_done; - } else if (WC_SUBLIST_TYPE(code) == WC_SUBLIST_END) + } else if (WC_SUBLIST_TYPE(code) == WC_SUBLIST_END) { donetrap = 1; + /* + * Treat this in the same way as if we reached + * the end of the sublist normally. + */ + state->pc = next; + goto sublist_done; + } } cmdpush(CS_CMDAND); break; @@ -877,8 +884,15 @@ execlist(Estate state, int dont_change_job, int exiting) * for this sublist. */ donetrap = 1; goto sublist_done; - } else if (WC_SUBLIST_TYPE(code) == WC_SUBLIST_END) + } else if (WC_SUBLIST_TYPE(code) == WC_SUBLIST_END) { donetrap = 1; + /* + * Treat this in the same way as if we reached + * the end of the sublist normally. + */ + state->pc = next; + goto sublist_done; + } } cmdpush(CS_CMDOR); break; diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst index c55ca4a83..026539307 100644 --- a/Test/A01grammar.ztst +++ b/Test/A01grammar.ztst @@ -319,3 +319,21 @@ done < /dev/null | { read name; print done } 0:Bug regression: `while' loop with redirection and pipeline >done + +# This used to be buggy and print X at the end of each iteration. + for f in 1 2 3 4; do + print $f || break + done && print X +0:Handling of ||'s and &&'s with a for loop in between +>1 +>2 +>3 +>4 +>X + +# Same bug for &&, used to print `no' at the end of each iteration + for f in 1 2 3 4; do + false && print strange + done || print no +0:Handling of &&'s and ||'s with a for loop in between +>no -- cgit 1.4.1