about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2019-05-03 20:34:53 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2019-05-03 20:34:53 +0100
commit588bb77cb674a192eb176c01c8d17db1e9e4aba2 (patch)
tree95a4001a8c63fca4bbe3bf276e27603ae1b3648b
parent8ce9e20c4963b288cee9a76523c41579880aeeb1 (diff)
downloadzsh-588bb77cb674a192eb176c01c8d17db1e9e4aba2.tar.gz
zsh-588bb77cb674a192eb176c01c8d17db1e9e4aba2.tar.xz
zsh-588bb77cb674a192eb176c01c8d17db1e9e4aba2.zip
44271: Fix breaks propagated from until or return.
If the until or return test caused continuation but there was
a pending return, breaks didn't get cancelled causing enclosing
scope to skip commands.
-rw-r--r--ChangeLog6
-rw-r--r--Src/loop.c8
-rw-r--r--Test/A01grammar.ztst10
3 files changed, 22 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 52b9bcd51..e0635dda8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-03  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 44271: Src/loop.c, Test/A01grammar.ztst: until with positive
+	and while with negative status propagated breaks too far after a
+	return, causing code in enclosing scope not to run.
+
 2019-04-26  dana  <dana@dana.is>
 
 	* 44234: Completion/Unix/Command/_ssh: Update for OpenSSH 8.0
diff --git a/Src/loop.c b/Src/loop.c
index 1013aeb50..3fa7006aa 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -425,7 +425,7 @@ execwhile(Estate state, UNUSED(int do_exec))
         breaks--;
 
         simple_pline = old_simple_pline;
-    } else
+    } else {
         for (;;) {
             state->pc = loop;
             noerrexit = NOERREXIT_EXIT | NOERREXIT_RETURN;
@@ -445,8 +445,11 @@ execwhile(Estate state, UNUSED(int do_exec))
 		    lastval = oldval;
                 break;
             }
-            if (retflag)
+            if (retflag) {
+		if (breaks)
+		    breaks--;
                 break;
+	    }
 
 	    /* In case the loop body is also a functional no-op,
 	     * make sure signal handlers recognize ^C as above. */
@@ -470,6 +473,7 @@ execwhile(Estate state, UNUSED(int do_exec))
             freeheap();
             oldval = lastval;
         }
+    }
     cmdpop();
     popheap();
     loops--;
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 339ce7494..1ed3cb6b7 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -640,6 +640,16 @@
 >1
 >0
 
+  echo 'echo dot
+  until return 42; do
+    :
+  done' >until_dot
+  . ./until_dot
+  echo After dot
+0:return in positive until test in dot file does not cause excess breaks
+>dot
+>After dot
+
   echo 'echo $?' >dot_status
   false
   . ./dot_status