zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [bug] wrong exit status upon (e) flag fatal errors in if/while conditions
Date: Wed, 5 May 2021 12:47:18 +0100 (BST)	[thread overview]
Message-ID: <1850011516.689067.1620215238829@mail2.virginmedia.com> (raw)
In-Reply-To: <20210505110713.zmny7625vlmog6ir@chazelas.org>

> On 05 May 2021 at 12:07 Stephane Chazelas <stephane@chazelas.org> wrote:
> $ a='${' zsh -c 'if : ${(e)a}; then echo x; fi; echo y'; echo $?
> zsh:1: bad substitution
> 0
> $ a='${' zsh -c 'if : ${(e)a}; then echo x; fi; echo y'; echo $?
> zsh:1: bad substitution
> 0
> 
> That's when the (e) flag is used in the condition part of an
> "if" or "while" (not "until") statement at least.
> 
> The shell aborts with an error message but with a success exit
> status.

I can do this one; it's quite obvious looking at the code, I think...

BTW this is somewhat obscurely cut and pasted, the actual commit
will come straight from the Linux machine, so don't worry about
any line endings here.

pws

diff --git a/Src/loop.c b/Src/loop.c
index 41b2e5627..aa733a2cb 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -583,7 +583,7 @@ execif(Estate state, int do_exec)
        cmdpop();
     } else {
        noerrexit = olderrexit;
-       if (!retflag)
+       if (!retflag && !errflag)
            lastval = 0;
     }
     state->pc = end;
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 35a04e7d5..88fc8606e 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -939,3 +939,8 @@ F:Note that the behaviour of 'exit' inside try-list inside a function is unspeci
  $ZTST_testdir/../Src/zsh -fc '{ ( ) } always { echo foo }'
 0:exec last command optimization inhibited for try/always
 >foo
+
+ a='${'
+ if : ${(e)a}; then echo x; fi
+1:Status on bad substitution in if without else
+?(eval):2: bad substitution


      reply	other threads:[~2021-05-05 11:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 11:07 Stephane Chazelas
2021-05-05 11:47 ` Peter Stephenson [this message]

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=1850011516.689067.1620215238829@mail2.virginmedia.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).