Source-Changes-HG archive

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

[src/trunk]: src/bin/sh More fallout from the fix for PR bin/48875 - this one...



details:   https://anonhg.NetBSD.org/src/rev/d76e8dacbe8e
branches:  trunk
changeset: 815358:d76e8dacbe8e
user:      kre <kre%NetBSD.org@localhost>
date:      Fri May 13 10:32:52 2016 +0000

description:
More fallout from the fix for PR bin/48875 - this one found just by
code reading, rather than any actual real use case failing.

With this script
        f()
        {
                echo hello $1
        }

        exec 3>&1
        echo $(
                for i in a b c
                do
                        echo @$i
                        f >&3
                done >/tmp/foo
        )
        echo foo= $(cat /tmp/foo)

what should be output is

        hello
        hello
        hello

        foo= @a @b @c

but since the (my) 48875 fix the other day, we've been getting

        hello
        @b
        hello
        @c
        hello

        foo= @a

This fixes that.   I think (hope) this is the last of these fixes...

diffstat:

 bin/sh/eval.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (33 lines):

diff -r 80287288e790 -r d76e8dacbe8e bin/sh/eval.c
--- a/bin/sh/eval.c     Fri May 13 10:24:42 2016 +0000
+++ b/bin/sh/eval.c     Fri May 13 10:32:52 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.126 2016/05/10 15:14:30 kre Exp $   */
+/*     $NetBSD: eval.c,v 1.127 2016/05/13 10:32:52 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.126 2016/05/10 15:14:30 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.127 2016/05/13 10:32:52 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -413,8 +413,13 @@
 
        loopnest++;
        for (sp = arglist.list ; sp ; sp = sp->next) {
+               int f = flags & (EV_TESTED | EV_MORE);
+
+               if (sp->next)
+                       f |= EV_MORE;
+
                setvar(n->nfor.var, sp->text, 0);
-               evaltree(n->nfor.body, flags & (EV_TESTED | EV_MORE));
+               evaltree(n->nfor.body, f);
                status = exitstatus;
                if (nflag)
                        break;



Home | Main Index | Thread Index | Old Index