1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-05-05 23:26:38 +02:00

52659: Fix crash on unset-through-nameref, add regression test

This commit is contained in:
Bart Schaefer 2024-03-04 21:21:20 -08:00
parent 700f675bf0
commit 0848b7534e
3 changed files with 32 additions and 2 deletions

View File

@ -1,5 +1,8 @@
2024-03-04 Bart Schaefer <schaefer@toltec-ubuntu>
* 52659: Src/builtin.c, Test/K01nameref.ztst: Fix crash when unset
was called on a named referece, add regression test
* 52650 plus minor fixes: Doc/Zsh/builtins.yo, Doc/Zsh/expn.yo,
Doc/Zsh/func.yo, Doc/Zsh/mod_ksh93.yo, Etc/FAQ.yo,
Src/Modules/ksh93.c, Src/builtin.c, Src/exec.c, Src/params.c,

View File

@ -3935,9 +3935,11 @@ bin_unset(char *name, char **argv, Options ops, int func)
int ref = (pm->node.flags & PM_NAMEREF);
if (!(pm = (Param)resolve_nameref(pm, NULL)))
continue;
if (ref && pm->level < locallevel) {
if (ref && pm->level < locallevel &&
!(pm->node.flags & PM_READONLY)) {
/* Just mark unset, do not remove from table */
pm->node.flags |= PM_DECLARED|PM_UNSET;
stdunsetfn(pm, 0);
pm->node.flags |= PM_DECLARED;
continue;
}
}

View File

@ -711,6 +711,31 @@ F:Checking for a bug in zmodload that affects later tests
>typeset -n ref=two
>typeset -n ref=var
typeset -g .K01.scalar='RW'
typeset -gA .K01.assoc=(x y)
typeset -ga .K01.array=(z)
typeset -gi .K01.integer=0
typeset -gE .K01.double=0.0
typeset -gF .K01.float=0.0
typeset -gr .K01.readonly='RO'
typeset -n gref
for gref in ARGC .K01.{scalar,assoc,array,integer,double,float,readonly}
do
{ unset gref } always { TRY_BLOCK_ERROR=0 }
done
typeset -p .K01.{scalar,assoc,array,integer,double,float,readonly}
unset .K01.{scalar,assoc,array,integer,double,float}
0:unset various types via nameref, including a readonly special
>typeset -g .K01.scalar
>typeset -g -A .K01.assoc
>typeset -g -a .K01.array
>typeset -g -i .K01.integer
>typeset -g -E .K01.double
>typeset -g -F .K01.float
>typeset -g -r .K01.readonly=RO
*?*read-only variable: ARGC
*?*read-only variable: .K01.readonly
unset -n ref
unset one
typeset -n ref