zsh-workers
 help / Atom feed
* [BUG] program flow corruption involving dot script and 'until' loop
@ 2019-05-03 17:20 Martijn Dekker
  2019-05-03 18:08 ` Mikael Magnusson
  2019-05-03 19:09 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Martijn Dekker @ 2019-05-03 17:20 UTC (permalink / raw)
  To: Zsh hackers list

===begin test.sh===
#! /bin/sh
fn() {
	echo beginfn
	. ./dot.sh
	echo endfn$?
}
echo begin
fn
echo end
===end test.sh===

===begin dot.sh===
#! /bin/sh
echo dot
until return 42; do
	:
done
===end dot.sh===

Actual output:
$ zsh test.sh
begin
beginfn
dot

Expected output:
$ zsh test.sh
begin
beginfn
dot
endfn42
end

Looks like the 'return' in the dot script causes zsh to just give up on 
the program altogether.

If 'return 42' is changed to 'return' in dot.sh, the bug disappears. If 
it is changed to '(exit 42); return', the bug re-appears.

I've tested zsh versions down to 5.0.6; they all act identically.

- M.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] program flow corruption involving dot script and 'until' loop
  2019-05-03 17:20 [BUG] program flow corruption involving dot script and 'until' loop Martijn Dekker
@ 2019-05-03 18:08 ` Mikael Magnusson
  2019-05-03 19:09 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2019-05-03 18:08 UTC (permalink / raw)
  To: Martijn Dekker; +Cc: Zsh hackers list

On 5/3/19, Martijn Dekker <martijn@inlv.org> wrote:
> ===begin test.sh===
> #! /bin/sh
> fn() {
> 	echo beginfn
> 	. ./dot.sh
> 	echo endfn$?
> }
> echo begin
> fn
> echo end
> ===end test.sh===
>
> ===begin dot.sh===
> #! /bin/sh
> echo dot
> until return 42; do
> 	:
> done
> ===end dot.sh===
>
> Actual output:
> $ zsh test.sh
> begin
> beginfn
> dot
>
> Expected output:
> $ zsh test.sh
> begin
> beginfn
> dot
> endfn42
> end
>
> Looks like the 'return' in the dot script causes zsh to just give up on
> the program altogether.
>
> If 'return 42' is changed to 'return' in dot.sh, the bug disappears. If
> it is changed to '(exit 42); return', the bug re-appears.
>
> I've tested zsh versions down to 5.0.6; they all act identically.

If I run this interactively
. =(echo until return 1\; do done)
it returns 1 immediately but I am no longer able to invoke any user
widgets (which in my case is both self-insert and accept-line, so it
is quite limiting :).

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] program flow corruption involving dot script and 'until' loop
  2019-05-03 17:20 [BUG] program flow corruption involving dot script and 'until' loop Martijn Dekker
  2019-05-03 18:08 ` Mikael Magnusson
@ 2019-05-03 19:09 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2019-05-03 19:09 UTC (permalink / raw)
  To: zsh-workers

On Fri, 2019-05-03 at 18:20 +0100, Martijn Dekker wrote:
> Looks like the 'return' in the dot script causes zsh to just give up on 
> the program altogether.

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-03 17:20 [BUG] program flow corruption involving dot script and 'until' loop Martijn Dekker
2019-05-03 18:08 ` Mikael Magnusson
2019-05-03 19:09 ` Peter Stephenson

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/ public-inbox