Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: crash with nameref and local argv
- X-seq: zsh-workers 54035
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: crash with nameref and local argv
- Date: Wed, 5 Nov 2025 06:22:59 +0100
- Archived-at: <https://zsh.org/workers/54035>
- In-reply-to: <CAH+w=7YWh4nS__qzBEb3i9_OYfTkYfqLYSigEp+Obyp6_K+nDg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAHYJk3Qe7XuGv_B8nFUdHLD4C_kSgaJkS5acAFWTJ2Db_GWoUQ@mail.gmail.com> <CAHYJk3RW-a5_sG4sc4pN-X3=Q1AQ2rZbBsKidWXEBzJps8piZw@mail.gmail.com> <CAH+w=7YuE2GzH1F9r9Q6WmJxk1puj1M1qmSLsQ76pJ2r+49r4g@mail.gmail.com> <CAH+w=7YWh4nS__qzBEb3i9_OYfTkYfqLYSigEp+Obyp6_K+nDg@mail.gmail.com>
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