Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh When a return occurs in the test part of a loop state...



details:   https://anonhg.NetBSD.org/src/rev/b1904f5b2a93
branches:  trunk
changeset: 456327:b1904f5b2a93
user:      kre <kre%NetBSD.org@localhost>
date:      Sat May 04 02:52:55 2019 +0000

description:
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:

 bin/sh/eval.c |  6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diffs (27 lines):

diff -r 18303bc51be2 -r b1904f5b2a93 bin/sh/eval.c
--- a/bin/sh/eval.c     Sat May 04 02:52:22 2019 +0000
+++ b/bin/sh/eval.c     Sat May 04 02:52:55 2019 +0000
@@ -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 @@
                        }
                        if (evalskip == SKIPBREAK && --skipcount <= 0)
                                evalskip = SKIPNONE;
+                       if (evalskip == SKIPFUNC || evalskip == SKIPFILE)
+                               status = exitstatus;
                        break;
                }
                if (n->type == NWHILE) {



Home | Main Index | Thread Index | Old Index