From e8147e0ce2fbef42c362c1e27c1c8c0f613cb49a Mon Sep 17 00:00:00 2001 From: kre Date: Sat, 4 May 2019 02:52:55 +0000 Subject: 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. --- bin/sh/eval.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'bin') 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) { -- cgit