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

[PATCH] Altering target of named reference when target is initially unset



This is a bit obscure, but leads to a crash.  See test case.
diff --git a/Src/builtin.c b/Src/builtin.c
index 5c5adb9d3..dd352c146 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2031,8 +2031,10 @@ typeset_single(char *cname, char *pname, Param pm, int func,
     char *subscript;
 
     if (pm && (pm->node.flags & PM_NAMEREF) && !((off|on) & PM_NAMEREF)) {
-	if (!(off & PM_NAMEREF))
-	    pm = (Param)resolve_nameref(pm, NULL);
+	if (!(off & PM_NAMEREF)) {
+	    if ((pm = (Param)resolve_nameref(pm, NULL)))
+		pname = pm->node.nam;
+	}
 	if (pm && (pm->node.flags & PM_NAMEREF) &&
 	    (on & ~(PM_NAMEREF|PM_LOCAL|PM_READONLY))) {
 	    /* Changing type of PM_SPECIAL|PM_AUTOLOAD is a fatal error.  *
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index d8c098a98..ebb70dd92 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -64,6 +64,17 @@ F:Other type changes are fatal errors, should this also be?
  typeset -p ptr var
 0:change type of referenced var
 >typeset -n ptr=var
+>typeset -t var
+
+ typeset var
+ unset var
+ typeset -n ptr=var
+ typeset -t ptr
+ typeset -p ptr var
+0:change type of unset referenced var
+F:regression - at one time this incorrectly applied the tag to "ptr"
+F:note this causes "var" to become set
+>typeset -n ptr=var
 >typeset -t var
 
  typeset -n ptr=var[2]


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