1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-11 13:01:28 +02:00

21678: Unsetting tied parameters caused various crashes

This commit is contained in:
Peter Stephenson 2005-08-22 11:43:36 +00:00
parent 7df83c6a1c
commit 635b405c55
3 changed files with 53 additions and 3 deletions

View file

@ -1,5 +1,8 @@
2005-08-22 Peter Stephenson <pws@csr.com> 2005-08-22 Peter Stephenson <pws@csr.com>
* 21678: Src/params.c, Test/D04parameter.ztst: unsetting
tied parameters was fraught with crashes.
* 21676: Doc/zmacros.yo, Doc/Zsh/contrib.yo, * 21676: Doc/zmacros.yo, Doc/Zsh/contrib.yo,
Functions/Zle/.distfiles, Functions/Zle/insert-composed-char, Functions/Zle/.distfiles, Functions/Zle/insert-composed-char,
Functions/Zle/insert-unicode-char: insert-unicode-char is now Functions/Zle/insert-unicode-char: insert-unicode-char is now

View file

@ -2342,6 +2342,7 @@ mod_export int
unsetparam_pm(Param pm, int altflag, int exp) unsetparam_pm(Param pm, int altflag, int exp)
{ {
Param oldpm, altpm; Param oldpm, altpm;
char *altremove;
if ((pm->flags & PM_READONLY) && pm->level <= locallevel) { if ((pm->flags & PM_READONLY) && pm->level <= locallevel) {
zerr("read-only variable: %s", pm->nam, 0); zerr("read-only variable: %s", pm->nam, 0);
@ -2351,13 +2352,20 @@ unsetparam_pm(Param pm, int altflag, int exp)
zerr("%s: restricted", pm->nam, 0); zerr("%s: restricted", pm->nam, 0);
return 1; return 1;
} }
if (pm->ename && !altflag)
altremove = ztrdup(pm->ename);
else
altremove = NULL;
if (!(pm->flags & PM_UNSET))
pm->gsu.s->unsetfn(pm, exp); pm->gsu.s->unsetfn(pm, exp);
if (pm->env) if (pm->env)
delenv(pm); delenv(pm);
/* remove it under its alternate name if necessary */ /* remove it under its alternate name if necessary */
if (pm->ename && !altflag) { if (altremove) {
altpm = (Param) paramtab->getnode(paramtab, pm->ename); altpm = (Param) paramtab->getnode(paramtab, altremove);
/* tied parameters are at the same local level as each other */ /* tied parameters are at the same local level as each other */
oldpm = NULL; oldpm = NULL;
while (altpm && altpm->level > pm->level) { while (altpm && altpm->level > pm->level) {
@ -2373,6 +2381,8 @@ unsetparam_pm(Param pm, int altflag, int exp)
} }
unsetparam_pm(altpm, 1, exp); unsetparam_pm(altpm, 1, exp);
} }
zsfree(altremove);
} }
/* /*
@ -2438,6 +2448,8 @@ stdunsetfn(Param pm, UNUSED(int exp))
pm->u.str = NULL; pm->u.str = NULL;
break; break;
} }
if (!(pm->flags & PM_SPECIAL))
pm->flags &= ~PM_TIED;
pm->flags |= PM_UNSET; pm->flags |= PM_UNSET;
} }
@ -2815,6 +2827,7 @@ tiedarrunsetfn(Param pm, UNUSED(int exp))
zsfree(pm->ename); zsfree(pm->ename);
pm->ename = NULL; pm->ename = NULL;
pm->flags &= ~PM_TIED; pm->flags &= ~PM_TIED;
pm->flags |= PM_UNSET;
} }
/**/ /**/

View file

@ -568,6 +568,40 @@
>0 >0
>/elsewhere /somewhere >/elsewhere /somewhere
local STRING=a:b
typeset -T STRING string
print $STRING $string
unset STRING
set -A string x y z
print $STRING $string
STRING=a:b
typeset -T STRING string
print $STRING $string
unset STRING
set -A string x y z
print $STRING $string
STRING=a:b
typeset -T STRING string
print $STRING $string
unset string
STRING=x:y:z
print $STRING $string
STRING=a:b
typeset -T STRING string
print $STRING $string
unset string
STRING=x:y:z
print $STRING $string
0:Unsetting and recreation of tied normal parameters
>a:b a b
>x y z
>a:b a b
>x y z
>a:b a b
>x:y:z
>a:b a b
>x:y:z
string='look for a match in here' string='look for a match in here'
if [[ ${string%%(#b)(match)*} = "look for a " ]]; then if [[ ${string%%(#b)(match)*} = "look for a " ]]; then
print $match[1] $mbegin[1] $mend[1] $string[$mbegin[1],$mend[1]] print $match[1] $mbegin[1] $mend[1] $string[$mbegin[1],$mend[1]]