aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2014-10-06 21:22:43 +0800
committerBen Hutchings <ben@decadent.org.uk>2020-03-28 21:42:54 +0000
commit020270d27f71a91afa9238152fe55da2dbcb5800 (patch)
tree0d0eea10f65ffedec1c1d494995f15ab446305d0
parent9a10962c04d36abbeaa11ca47227f6ca6cacd1ce (diff)
downloadklibc-020270d27f71a91afa9238152fe55da2dbcb5800.tar.gz
[klibc] dash: [BUILTIN] Allow return in loop conditional to set exit status
[ dash commit f14b4626eb5c1c2fda137e7d1520c5f1cb7e85c4 ] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=332954 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@smarden.org>. Reported-by: Stephane Chazelas <stephane_chazelas@yahoo.fr> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--usr/dash/eval.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index 6cc92c1923c10..bb9fc260a5108 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;
loopnest--;
- exitstatus = status;
}