[klibc] [klibc:update-dash] dash: [BUILTIN] Allow return in loop conditional to set exit status

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Sat Mar 28 14:48:22 PDT 2020

Commit-ID:  020270d27f71a91afa9238152fe55da2dbcb5800
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=020270d27f71a91afa9238152fe55da2dbcb5800
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Mon, 6 Oct 2014 21:22:43 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 21:42:54 +0000

[klibc] dash: [BUILTIN] Allow return in loop conditional to set exit status

[ dash commit f14b4626eb5c1c2fda137e7d1520c5f1cb7e85c4 ]


When return is used in a loop conditional the exit status will
be lost because we always set the exit status at the end of the
loop to that of the last command executed in the body.

This is counterintuitive and contrary to what most other shells do.

This patch fixes this by always preserving the exit status of
return when it is used in a loop conditional.

The patch was originally written by Gerrit Pape <pape at smarden.org>.

Reported-by: Stephane Chazelas <stephane_chazelas at yahoo.fr>
Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

 usr/dash/eval.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index 6cc92c19..bb9fc260 100644
--- a/usr/dash/eval.c
+++ b/usr/dash/eval.c
@@ -387,8 +387,9 @@ evalloop(union node *n, int flags)
 		status = exitstatus;
 		skip = skiploop();
 	} while (!(skip & ~SKIPCONT));
+	if (skip != SKIPFUNC)
+		exitstatus = status;
-	exitstatus = status;

More information about the klibc mailing list