Module Name:    src
Committed By:   kre
Date:           Sat May  4 02:52:55 UTC 2019

Modified Files:
        src/bin/sh: eval.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/bin/sh/eval.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.174 src/bin/sh/eval.c:1.175
--- src/bin/sh/eval.c:1.174	Sat Feb  9 09:17:59 2019
+++ src/bin/sh/eval.c	Sat May  4 02:52:55 2019
@@ -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) {

Reply via email to