zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Bug in alias expansion
Date: Sun, 15 Nov 2015 20:03:56 +0000	[thread overview]
Message-ID: <20151115200356.0f3a80a2@ntlworld.com> (raw)
In-Reply-To: <CAFvQaj4AKN36Ntdxt0rNCqPxWFHtjLMt3zPK65y2Xf9G5iUfWA@mail.gmail.com>

On Fri, 13 Nov 2015 13:03:52 -0500
Kynn Jones <kynnjo@gmail.com> wrote:
> % typeset -A frobozz
> % alias -g foo='echo xyz'
> % frobozz[$(foo)]=9
> zsh: not an identifier: frobozz[$(fooech9

This is somewhere in the vicinity of parse_subscript().  That's called
both from isident() and getindex(); I got as far as the case called from
isident(), but it may be the second one gets called, too.  The
suspicious bit in parse_subscript() is this:

    strinbeg(0);
    lexbuf.len = 0;
    lexbuf.ptr = tokstr = s;
    lexbuf.siz = l + 1;
    err = dquote_parse(endchar, sub);
    if (err) {
	err = *lexbuf.ptr;
	*lexbuf.ptr = '\0';
	untokenize(s);
	*lexbuf.ptr = err;
	s = NULL;
    } else {
	s = lexbuf.ptr;
    }
    strinend();

This is assuming the tokstr you get back is the same you sent down,
which it may not because it might need reallocating --- it does indeed
in this case because we are expanding an alias inside.  It confused me a
bit that it's only the end of the string (s, from lexbuf.ptr) that's
being passed back, but that's presumably because it's assuming the start
doesn't move, which is the (or an) erroneous assumption.  It's possible
the fix therefore is simply ensuring that both the start and the end of
the string are pased back and the start passed in forgotten.

Howver, I don't really understand the !ss[1] test (ss is the pointer
passed back) in isident(): it seems to assume the ']' or whatever else
comes at the end of the LHS of the assignment, has been separated off
from anything else, which possibly happens higher up.  When I walked
through this there didn't appear to be any reason why the next character
would be a null since I couldn't see dquote_parse() adding one and I
don't think we've even got that far in reading the input supplied for
this case (as it's only parsing as far as endchar) --- but this may be
part of the same assumption that we've still got the string passed in
down below.  So it's possible it's making even dodgier assumptions that
if you write the output first then something magic is going to happen
about the later parts of it, which it doesn't always.  (Note that the
input is at least a duplicated version of the string being used as the
output area, it's not the "s" in the chunk above itself.)  This might,
for example, be a shortcut instead of testing for end of input after the
']'.  So possibly making parse_subscript() get the next input and look
to see if it's after the end. then passing that back, is also necessary.

I don't know why this works in other contexts.

dquote_parse() has got some comments at the top that look like me trying
to work out what the heck it actually does, which is a bad sign.

Note initial parsing worked OK --- it's got as far as attempting to
evaluate the subscript for the assignment.  Sot it must be broken
assumptions later on rather than failure in the loewr layers.

pws


  parent reply	other threads:[~2015-11-15 20:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-13 18:03 Kynn Jones
2015-11-14  1:03 ` Bart Schaefer
2015-11-14 18:57   ` Kynn Jones
2015-11-14 19:03     ` Bart Schaefer
2015-11-14 19:19       ` Kynn Jones
2015-11-14 21:40         ` Bart Schaefer
2015-11-14 22:20           ` Kynn Jones
2015-11-15 20:03 ` Peter Stephenson [this message]
2015-11-15 21:52   ` Bart Schaefer
2015-11-15 22:26     ` Bart Schaefer
2015-11-15 22:48   ` Bart Schaefer
2015-11-16  0:50     ` Mikael Magnusson
2015-11-16  3:24       ` Bart Schaefer
2015-11-16  5:42         ` Mikael Magnusson
2015-11-18 10:42     ` Peter Stephenson
2015-11-18 14:13       ` Peter Stephenson
2015-11-18 15:52         ` Bart Schaefer
2015-11-18 16:14           ` Peter Stephenson
2015-11-18 18:09             ` Bart Schaefer
2015-11-17 17:29   ` Peter Stephenson
2015-11-18  4:55     ` Bart Schaefer
2015-11-18 10:30       ` Peter Stephenson

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=20151115200356.0f3a80a2@ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).