mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-11-27 15:01:00 +01:00
53676+54009: Revise 52650+51945 for assignment to global through nameref
Allows assignment to a global via nameref to succeed without creating a dereference loop. Update tests for changed behavior.
This commit is contained in:
parent
b66a2e2524
commit
005ef2c830
3 changed files with 30 additions and 9 deletions
|
|
@ -23,6 +23,10 @@
|
|||
* Philippe: 53798: Src/params.c, Src/zsh.h, Test/K01nameref.ztst:
|
||||
report reference loops created when a reference goes out of scope
|
||||
|
||||
* Philippe: 53676 (test tweaked per 54009): Src/params.c,
|
||||
Test/K01nameref.ztst: Revise 52650+51945 to allow assignment to
|
||||
global through nameref without looping
|
||||
|
||||
2025-10-24 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* 54002: Src/parse.c: silence compiler warning for static function
|
||||
|
|
|
|||
|
|
@ -1044,13 +1044,12 @@ createparam(char *name, int flags)
|
|||
if (oldpm && !(flags & PM_NAMEREF) &&
|
||||
(oldpm->level == locallevel ?
|
||||
!(oldpm->node.flags & PM_RO_BY_DESIGN) : !(flags & PM_LOCAL)) &&
|
||||
(oldpm->node.flags & PM_NAMEREF) &&
|
||||
(oldpm = upscope(oldpm, oldpm->base))) {
|
||||
(oldpm->node.flags & PM_NAMEREF)) {
|
||||
Param lastpm;
|
||||
struct asgment stop;
|
||||
stop.flags = PM_NAMEREF;
|
||||
stop.name = oldpm->node.nam;
|
||||
stop.value.scalar = GETREFNAME(oldpm);
|
||||
stop.name = "";
|
||||
stop.value.scalar = NULL;
|
||||
lastpm = (Param)resolve_nameref(oldpm, &stop);
|
||||
if (lastpm) {
|
||||
if (lastpm->node.flags & PM_NAMEREF) {
|
||||
|
|
|
|||
|
|
@ -881,6 +881,21 @@ F:Checking for a bug in zmodload that affects later tests
|
|||
>typeset -n ref=var
|
||||
>typeset -g var=RESET
|
||||
|
||||
unset -n ref
|
||||
unset var1
|
||||
typeset -n ref=var1
|
||||
() {
|
||||
typeset -n ref=var2
|
||||
ref=RESET
|
||||
typeset -p ref var2
|
||||
}
|
||||
typeset -p ref var2
|
||||
0:local reference hides same-name global reference
|
||||
>typeset -n ref=var2
|
||||
>typeset -g var2=RESET
|
||||
>typeset -n ref=var1
|
||||
>typeset -g var2=RESET
|
||||
|
||||
unset -n ref
|
||||
unset one
|
||||
typeset -n ref
|
||||
|
|
@ -1045,14 +1060,17 @@ F:relies on global TYPESET_TO_UNSET in %prep
|
|||
() {
|
||||
typeset -n foo; foo=zz
|
||||
foo=zz || print -u2 foo: assignment failed
|
||||
print $bar $zz
|
||||
typeset -p bar zz
|
||||
}
|
||||
() { typeset -n foo; foo=zz; local zz; foo=zz; print $bar $zz }
|
||||
# prior to workers/53676 the assignment failed
|
||||
unset zz
|
||||
() { typeset -n foo; foo=zz; local zz; foo=zz; typeset -p bar zz }
|
||||
0:regression: local nameref may not in-scope a global parameter
|
||||
F:previously this could create an infinite recursion and crash
|
||||
>xx
|
||||
>xx zz
|
||||
*?*foo: assignment failed
|
||||
>typeset -g bar=xx
|
||||
>typeset -g zz=zz
|
||||
>typeset -g bar=xx
|
||||
>typeset zz=zz
|
||||
|
||||
typeset -nm foo=bar
|
||||
1:create nameref by pattern match not allowed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue