zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Peter Stephenson <p.stephenson@samsung.com>
Cc: zsh-workers@zsh.org
Subject: Re: Bug Report: Variable becomes unset without reason
Date: Wed, 14 Aug 2019 17:12:19 +0200	[thread overview]
Message-ID: <CAHYJk3RB8NnY4mA1+LuYLaw-P-vG8s6ezRpEvRmu8NtkuZtqkA@mail.gmail.com> (raw)
In-Reply-To: <1565791473.4796.6.camel@samsung.com>

On 8/14/19, Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Wed, 2019-08-14 at 10:37 +0100, Stephane Chazelas wrote:
>> 2019-08-08 20:38:05 +0430, Aryn Starr:
>> Now, that being said, as discussed on U&L it looks like a bug
>> indeed and a shorter reproducer is:
>>
>> $ zsh -xc 'v=1; f() { local v; v=2 true; }; f; typeset -p v'
>> +zsh:1> v=1
>> +zsh:1> f
>> +f:0> local v
>> +f:0> v=2 +f:0> true
>> +zsh:1> typeset -p v
>> zsh:typeset:1: no such variable: v
>>
>> Most likely, that's the "v=2 true" (where "true" is a builtin) that ends
>> up
>> unsetting the "v" from the global scope.
>
> Yes, the saved version of "v" that we restore after the builtin is
> missing the pointer back to the version of v in the enclosing scope.  So
> it's not only not shown as set, it will leak memory.
>
> This simply preserves that pointer in the copy, but this assumes we've
> correctly blocked off the old parameter from being altered inside the
> function scope --- if we haven't that preserved old pointer is going to
> get us into trouble.  However, if we haven't that's already a bug, so
> this shouldn't make things worse.

This got me thinking about related stuff. I guess these results are
expected, maybe even at best unspecified?
% foo=initial; foo=bar printf -v foo hello; echo $foo
initial
% set hi; argv= set hello; echo $1
hi
% set a b c; argv= shift; echo $@
a b c
% a=1; a=5 typeset a=3 b=7; echo $a$b
17

-- 
Mikael Magnusson

      reply	other threads:[~2019-08-14 15:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 16:08 Aryn Starr
2019-08-14  9:37 ` Stephane Chazelas
2019-08-14 12:17   ` Aryn Starr
2019-08-14 14:04   ` Peter Stephenson
2019-08-14 15:12     ` Mikael Magnusson [this message]

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=CAHYJk3RB8NnY4mA1+LuYLaw-P-vG8s6ezRpEvRmu8NtkuZtqkA@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=p.stephenson@samsung.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).