From d946f22a4cd2eed0f3a67881cfa57c805703929c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 14 Aug 2019 15:16:59 +0100 Subject: 44664: Fix problem with temporary assignment. "foo=bar builtin" inside a function lost any variable from enclosing scope. --- ChangeLog | 6 ++++++ Src/params.c | 4 +++- Test/D04parameter.ztst | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 467b0683e..1cbd057e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2019-08-14 Peter Stephenson + + * 44664: Src/params.c, Test/D04parameter.ztst: Ensure + temporary assignment around builtin in function doesn't + trash global variable. + 2019-08-03 Peter Stephenson * 44635: Src/exec.c: don't apply STAT_NOPRINT to backgrounded diff --git a/Src/params.c b/Src/params.c index 1499e3a40..a253a9d8e 100644 --- a/Src/params.c +++ b/Src/params.c @@ -1124,8 +1124,10 @@ copyparam(Param tpm, Param pm, int fakecopy) tpm->base = pm->base; tpm->width = pm->width; tpm->level = pm->level; - if (!fakecopy) + if (!fakecopy) { + tpm->old = pm->old; tpm->node.flags &= ~PM_SPECIAL; + } switch (PM_TYPE(pm->node.flags)) { case PM_SCALAR: tpm->u.str = ztrdup(pm->gsu.s->getfn(pm)); diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 194c3e287..b6e85a9fe 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -2522,3 +2522,15 @@ F:behavior, see http://austingroupbugs.net/view.php?id=888 >trailing/slashes >removed >are/removed + + foo=global-value + fn() { + local foo=function-value + foo=export-value true + print $foo + } + fn + print $foo +0:Global variables are not trashed by "foo=bar builtin" (regression test) +>function-value +>global-value -- cgit 1.4.1