* [PATCH] Fix a WARN_CREATE_GLOBAL false positive.
@ 2013-12-06 7:47 Daniel Shahaf
2013-12-06 9:23 ` Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2013-12-06 7:47 UTC (permalink / raw)
To: zsh-workers
---
This seems to be a false positive:
% zsh -fc 'setopt warn_create_global; (){ x=y =true }'
(anon): scalar parameter x created globally in function
Regression test attached. I'm less sure about the patch, but it seems to
work and is unlikely to break anything other than WARN_CREATE_GLOBAL.
Daniel
Src/exec.c | 5 ++++-
Test/E01options.ztst | 1 +
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git Src/exec.c Src/exec.c
index df915e1..dccdc2b 100644
--- Src/exec.c
+++ Src/exec.c
@@ -3309,7 +3309,10 @@ execcmd(Estate state, int input, int output, int how, int last1)
}
if (type == WC_SIMPLE) {
if (varspc) {
- addvars(state, varspc, ADDVAR_EXPORT|ADDVAR_RESTRICT);
+ int addflags = ADDVAR_EXPORT|ADDVAR_RESTRICT;
+ if (forked)
+ addflags |= ADDVAR_RESTORE;
+ addvars(state, varspc, addflags);
if (errflag)
_exit(1);
}
diff --git Test/E01options.ztst Test/E01options.ztst
index e00eb0e..48f3ffc 100644
--- Test/E01options.ztst
+++ Test/E01options.ztst
@@ -1067,6 +1067,7 @@
fn2() {
foo3=bar6
}
+ foo4=bar7 =true
}
fn
0:WARN_CREATE_GLOBAL option
--
1.7.10.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix a WARN_CREATE_GLOBAL false positive.
2013-12-06 7:47 [PATCH] Fix a WARN_CREATE_GLOBAL false positive Daniel Shahaf
@ 2013-12-06 9:23 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2013-12-06 9:23 UTC (permalink / raw)
To: zsh-workers
On Fri, 06 Dec 2013 09:47:28 +0200
Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> This seems to be a false positive:
>
> % zsh -fc 'setopt warn_create_global; (){ x=y =true }'
> (anon): scalar parameter x created globally in function
>
> Regression test attached. I'm less sure about the patch, but it seems to
> work and is unlikely to break anything other than WARN_CREATE_GLOBAL.
> if (varspc) {
> - addvars(state, varspc, ADDVAR_EXPORT|ADDVAR_RESTRICT);
> + int addflags = ADDVAR_EXPORT|ADDVAR_RESTRICT;
> + if (forked)
> + addflags |= ADDVAR_RESTORE;
> + addvars(state, varspc, addflags);
> if (errflag)
> _exit(1);
> }
It looks plausible. "forked" is a local variable in execcmd() saying we
forked to execute whatever it is, so it indicates the variable can't
leak from the current command context. ADVAR_RESTORE is only a signal
to quieten the warning (it could be better named; the name comes from
the other time it's set rather than it's real purpose). So it certainly
looks better than before.
Thanks
pws
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-12-06 9:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-06 7:47 [PATCH] Fix a WARN_CREATE_GLOBAL false positive Daniel Shahaf
2013-12-06 9:23 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).