diff options
| author | kre <kre@NetBSD.org> | 2019-05-04 02:52:55 +0000 |
|---|---|---|
| committer | kre <kre@NetBSD.org> | 2019-05-04 02:52:55 +0000 |
| commit | e8147e0ce2fbef42c362c1e27c1c8c0f613cb49a (patch) | |
| tree | 98d403d92aa5c3a262313dfb7431ac5bbf821425 /bin | |
| parent | e31d68842d5626f22ea5ce8b59267abc49bf51cc (diff) | |
When a return occurs in the test part of a loop statement (while/until)
(inside a function or dot script) the exit status of that return
statement should become the exit status of the function (or dot
script) - we were ignoring it,
That is
fn() { while return 7; do return 9; done; return 11; }
should exit with status 7. It was exiting 0.
This is apparently another old ash bug that has been fixed
everywhere else in the past.
Issue pointed out by Martijn Dekker, (fairly obvious) fix borrowed
from FreeBSD, due for return sometime next century.
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/sh/eval.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 55468f3c7cb..e5b7b340c0d 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.174 2019/02/09 09:17:59 kre Exp $ */ +/* $NetBSD: eval.c,v 1.175 2019/05/04 02:52:55 kre Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.174 2019/02/09 09:17:59 kre Exp $"); +__RCSID("$NetBSD: eval.c,v 1.175 2019/05/04 02:52:55 kre Exp $"); #endif #endif /* not lint */ @@ -407,6 +407,8 @@ evalloop(union node *n, int flags) } if (evalskip == SKIPBREAK && --skipcount <= 0) evalskip = SKIPNONE; + if (evalskip == SKIPFUNC || evalskip == SKIPFILE) + status = exitstatus; break; } if (n->type == NWHILE) { |
