mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-05-22 12:21:29 +02:00
51430: Misc. problems with typeset and $parameters
* Fix and test for regression of assignment when using typeset command * Fix output of typeset +m and $parameters[ref] * Prevent segfault in typeset
This commit is contained in:
parent
f4c706f0c8
commit
03887bb03f
5 changed files with 33 additions and 8 deletions
|
@ -1,3 +1,10 @@
|
|||
2023-02-13 Bart Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 51430: Src/Modules/parameter.c, Src/builtin.c, Src/params.c,
|
||||
Test/K01nameref.ztst: Fix and test for regression of assignment
|
||||
when using typeset command, fix output of typeset +m and
|
||||
$parameters[ref], prevent segfault in typeset.
|
||||
|
||||
2023-02-12 Bart Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 51417: Src/params.c, Test/K01nameref.ztst: Check subscripts
|
||||
|
|
|
@ -108,7 +108,7 @@ getpmparameter(UNUSED(HashTable ht), const char *name)
|
|||
if ((rpm = (Param) realparamtab->getnode2(realparamtab, name)) &&
|
||||
!(rpm->node.flags & PM_UNSET)) {
|
||||
pm->u.str = paramtypestr(rpm);
|
||||
if ((rpm->node.flags & PM_NAMEREF) &&
|
||||
if ((rpm->node.flags & PM_NAMEREF) && rpm->u.str && *(rpm->u.str) &&
|
||||
(rpm = (Param) realparamtab->getnode(realparamtab, name)) &&
|
||||
!(rpm->node.flags & PM_UNSET)) {
|
||||
pm->u.str = zhtricat(pm->u.str, "-", paramtypestr(rpm));
|
||||
|
|
|
@ -2262,8 +2262,9 @@ typeset_single(char *cname, char *pname, Param pm, int func,
|
|||
*/
|
||||
if (!(on & PM_READONLY) || !isset(POSIXBUILTINS))
|
||||
off |= PM_UNSET;
|
||||
pm->node.flags = (pm->node.flags |
|
||||
(on & ~PM_READONLY)) & ~off;
|
||||
if (!OPT_ISSET(ops, 'p'))
|
||||
pm->node.flags = (pm->node.flags |
|
||||
(on & ~PM_READONLY)) & ~off;
|
||||
}
|
||||
if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z)) {
|
||||
if (typeset_setwidth(cname, pm, ops, on, 0))
|
||||
|
@ -3063,12 +3064,15 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
|
|||
if (asg->value.scalar &&
|
||||
((pm = (Param)resolve_nameref((Param)hn, asg)) &&
|
||||
(pm->node.flags & PM_NAMEREF))) {
|
||||
if (pm->node.flags & PM_SPECIAL)
|
||||
if (pm->node.flags & PM_SPECIAL) {
|
||||
zwarnnam(name, "%s: invalid reference", pm->node.nam);
|
||||
else
|
||||
returnval = 1;
|
||||
continue;
|
||||
} else if (pm->u.str && strcmp(pm->u.str, asg->name) == 0) {
|
||||
zwarnnam(name, "%s: invalid self reference", asg->name);
|
||||
returnval = 1;
|
||||
continue;
|
||||
returnval = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (hn) {
|
||||
/* namerefs always start over fresh */
|
||||
|
|
|
@ -5851,7 +5851,7 @@ static const struct paramtypes pmtypes[] = {
|
|||
{ PM_EXPORTED, "exported", 'x', 0},
|
||||
{ PM_UNIQUE, "unique", 'U', 0},
|
||||
{ PM_TIED, "tied", 'T', 0},
|
||||
{ PM_NAMEREF, "namref", 'n', 0}
|
||||
{ PM_NAMEREF, "nameref", 'n', 0}
|
||||
};
|
||||
|
||||
#define PMTYPES_SIZE ((int)(sizeof(pmtypes)/sizeof(struct paramtypes)))
|
||||
|
|
|
@ -25,6 +25,20 @@
|
|||
0:assign nameref placeholder
|
||||
>ptr=var
|
||||
|
||||
unset ptr
|
||||
typeset -n ptr
|
||||
typeset -n ptr=var
|
||||
typeset -n
|
||||
0:assign placeholder with new typeset
|
||||
>ptr=var
|
||||
|
||||
typeset -n ptr1
|
||||
typeset -n ptr2=ptr1
|
||||
typeset -n
|
||||
0:chain ending in placeholder
|
||||
>ptr1
|
||||
>ptr2=ptr1
|
||||
|
||||
typeset ptr=var
|
||||
typeset -n ptr
|
||||
typeset -n
|
||||
|
|
Loading…
Reference in a new issue