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

Re: [PATCH] Fix crash on unset-through-nameref



2024-03-03 21:37:34 -0800, Bart Schaefer:
> On Sun, Mar 3, 2024 at 2:58 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > On Sun, Mar 3, 2024 at 12:27 PM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> > >
> > > It segfaults with zsh -x though
> >
> > I'll have a look at that later, thanks.
> 
> Variation of the same problem reported by Jun T. when unsetting the
> array part of a tied pair.
[...]

Thanks. That seems to fix it.

There's however a behaviour I can't explain:

$ ./Src/zsh -c 'f() { typeset -n v=$1; unset v; typeset -p w; v=(); }; w=1; f w; typeset -p w'
typeset -g w
typeset -a w=(  )
$ ./Src/zsh -c 'f() { typeset -n v=$1; unset v; typeset -p w; v=(); }; v=1; w=1; f w; typeset -p w'
typeset -g w
f: w: attempt to assign array value to non-array

The behaviour of that v=() seems to be influenced by the fact
that v was declared as scalar in the global scope.

See also:

$ ./Src/zsh -c 'myunset() { typeset -n v=$1; unset v; }; export x=1; myunset x; typeset -p x; x=2; typeset -p x'
export x
export x=2

That shows an unset through a nameref in a different scope
doesn't do a full unset: the variable remains declared and
retains its attributes (also evidenced by that "typeset -p w").

-- 
Stephane




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