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

Re: crash with nameref and local argv



On Tue, Nov 4, 2025 at 9:26 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Mon, Nov 3, 2025 at 8:53 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > > On Tue, Jun 10, 2025 at 1:11 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > > >
> > > > % () { local argv=( $argv ); typeset -nu foo=argv; echo $foo }
> >
> > You can't make a named reference to the parent's argv
> > array, because that doesn't exist "below" its original scope
>
> Brute-force way to fix this follows.  If we run into more special
> cases it might be worth passing flags to valid_refname().
>
> diff --git a/Src/params.c b/Src/params.c
> index 5a0434e40..444630db9 100644
> --- a/Src/params.c
> +++ b/Src/params.c
> @@ -3239,7 +3239,8 @@ assignsparam(char *s, char *val, int flags)
>         return NULL;
>      }
>      if (*val && (v->pm->node.flags & PM_NAMEREF)) {
> -       if (!valid_refname(val)) {
> +       if (!valid_refname(val) ||
> +           ((v->pm->node.flags & PM_UPPER) && !strcmp(val, "argv"))) {
>             zerr("invalid variable name: %s", val);
>             zsfree(val);
>             unqueue_signals();

Would that break this code (which currently works)?
% () { local -h argv=hello; () { local argv=( $argv ); typeset -nu
foo=argv; echo $foo } } noot
hello

-- 
Mikael Magnusson




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