zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Altering target of named reference when target is initially unset
Date: Sat, 17 Feb 2024 20:16:04 -0800	[thread overview]
Message-ID: <CAH+w=7bdwBNYCjP4kmh6GASQwjtUdLR4EJOQwuPP9ccXAr44tA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 61 bytes --]

This is a bit obscure, but leads to a crash.  See test case.

[-- Attachment #2: nameref2unset.txt --]
[-- Type: text/plain, Size: 1264 bytes --]

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]

                 reply	other threads:[~2024-02-18  4:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bdwBNYCjP4kmh6GASQwjtUdLR4EJOQwuPP9ccXAr44tA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).