diff mbox series

eval: Test evalskip before flipping status for NNOT

Message ID Y5BU6+7igxd21p8o@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series eval: Test evalskip before flipping status for NNOT | expand

Commit Message

Herbert Xu Dec. 7, 2022, 8:55 a.m. UTC
On Tue, Dec 06, 2022 at 10:15:03AM +0000, Harald van Dijk wrote:
> 
> There is a long-standing bug that may or may not be harder to fix if this
> patch goes in, depending on how you want to fix it. Here's a script that
> already fails on current dash.
> 
>   f() {
>     if ! return 0
>     then :
>     fi
>   }
>   f
> 
> This should return 0, and does return 0 in bash and ksh (and almost all
> shells), but returns 1 in dash.
> 
> There are a few possible ways of fixing it. Some of them rely on continuing
> to conditionally set exitstatus.

This can be fixed simply by testing evalskip prior to flipping the
status.

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff mbox series

Patch

diff --git a/src/eval.c b/src/eval.c
index 7aa5cc2..fa43b68 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -238,7 +238,9 @@  evaltree(union node *n, int flags)
 		break;
 #endif
 	case NNOT:
-		status = !evaltree(n->nnot.com, EV_TESTED);
+		status = evaltree(n->nnot.com, EV_TESTED);
+		if (!evalskip)
+			status = !status;
 		break;
 	case NREDIR:
 		errlinno = lineno = n->nredir.linno;