zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: "set -e" handling is broken with zsh 5.3.1 and 5.4.1
Date: Sun, 27 Aug 2017 19:56:48 +0100	[thread overview]
Message-ID: <20170827195648.6f078249@ntlworld.com> (raw)
In-Reply-To: <20170827005040.GA12622@zira.vinc17.org>

On Sun, 27 Aug 2017 02:50:40 +0200
Vincent Lefevre <vincent@vinc17.net> wrote:
> Consider:
> 
> ----------------------------------------
> #!/usr/bin/env zsh
> 
> set -e
> 
> f()
> {
>   [[ -z 1 ]] && false
> }
> 
> if false; then
>   :
> else
>   f
>   echo Fail 1
>   echo Fail 2
>   f
>   echo Fail 3
> fi
> ----------------------------------------
> 
> With
>   zsh 5.3.1-4+b1 under Debian/stretch
>   zsh 5.4.1-1 under Debian/unstable
> 
> I get:
> 
> % ./cond2-e; echo $?
> Fail 1
> Fail 2
> 1
> 
> I suppose that cond2-e should die just after f is called, before
> outputting anything.

Yes, I would say so.

This appears to have been deliberate, in that after "if" we usually
restore noerrexit beahaviour on the first thing we execute, but if it's
a function we don't.  However, I can't for the life of me work out why I
made that exeception --- certainly nothing goes wrong in the tests if I
apply the following, and I would expect to be testing whatever it was
made me think we needed the qualification.  It might have been to do
with empty functions, but making f empty, so it runs but doesn't change
the status, doesn't seem to do anything unexpected (we shouldn't
and don't exit).

I think I'll apply the effect of this after the release of 5.4.2, with a
test based on the code above plus some empty functions just in case, and
see what happens.

In the mean time somebody may find a more fiendish variant involving
functions that causes a further problem.

pws

diff --git a/Src/exec.c b/Src/exec.c
index cd99733..82277a3 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3025,7 +3025,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 	preargs = NULL;
 
     /* if we get this far, it is OK to pay attention to lastval again */
-    if ((noerrexit & NOERREXIT_UNTIL_EXEC) && !is_shfunc)
+    if ((noerrexit & NOERREXIT_UNTIL_EXEC)/* && !is_shfunc*/)
 	noerrexit = 0;
 
     /* Do prefork substitutions.


  parent reply	other threads:[~2017-08-27 19:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-27  0:50 Vincent Lefevre
2017-08-27  1:30 ` Daniel Shahaf
2017-08-27  1:46   ` Vincent Lefevre
2017-08-27 18:56 ` Peter Stephenson [this message]
2017-08-27 22:26   ` Vincent Lefevre
2017-08-28  1:25     ` Daniel Shahaf
2017-08-28  6:45       ` Bart Schaefer
2017-08-28 20:56         ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170827195648.6f078249@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).