Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Fix a WARN_CREATE_GLOBAL false positive.



On Fri, 06 Dec 2013 09:47:28 +0200
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> 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



Messages sorted by: Reverse Date, Date, Thread, Author