zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: Re: PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
Date: Thu, 18 Feb 1999 12:05:59 +0100 (MET)	[thread overview]
Message-ID: <199902181105.MAA07404@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: "Bart Schaefer"'s message of Fri, 12 Feb 1999 23:05:07 -0800


Bart Schaefer wrote:

> On Feb 12,  9:33am, Bart Schaefer wrote:
> } Subject: Re: PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
> } 
> } zagzig% foo() { echo $# "$@" }
> } zagzig% foo "$unset[@]"
> } zsh: segmentation fault (core dumped)  Src/zsh -f
> 
> Here's a fix.  I don't think this can possibly cause anything else to go
> wrong, but ...

...it broke multiple subscripts. The patch below fixes this in a way
that hopefully will not cause anything else to go wrong, but...

Seriously, the problem was that for multiple subscripts a temporary
pm-struct was created with a NULL nam. The patch makes such a
temporary get a nam equal to nulstring. Since such a temporary is
created only in one place this should not affect other uses (of
createparam() and getarrvalue()).

I found this while trying to `fix' the problem I mentioned in 7328:

Given an array `a=(a b b c d e f g)' an expression like this

  ${${a[1,4]}[(I)b]}

gives `3' (the offset of the last `b' in the first four
elements). But if the expression is used inside a subscript:

  ${a[${${a[1,4]}[(I)b]},-1]}

this returns the whole string because the first expression expands to
`0' (zero). This is caused by the call to parsestr() in getarg() which
makes the subscript be tokenized as if it where in double quotes. With
that the code in paramsubst() and friends turns ${a[1,4]} into one
string, making the [(I)b] fail. To get this to work one will have to
use ${a[${${(@)a[1,4]}[(I)b]},-1]}.

I don't want to change this now because I think that there are reasons
to use parsestr() instead of parse_subst_string() (which solves the
problem), but I think that this difference between using the same
expression outside of an subscript and inside one is quite irritating.
So, does anyone know of a case where we need the behavior parsestr()
gives?


Bye
 Sven

--- os/params.c	Mon Feb 15 12:51:43 1999
+++ Src/params.c	Thu Feb 18 11:20:15 1999
@@ -568,8 +568,10 @@
 
 	if (isset(ALLEXPORT) && !oldpm)
 	    flags |= PM_EXPORTED;
-    } else
+    } else {
 	pm = (Param) alloc(sizeof *pm);
+	pm->nam = nulstring;
+    }
     pm->flags = flags;
 
     if(!(pm->flags & PM_SPECIAL))

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


             reply	other threads:[~1999-02-18 11:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-18 11:05 Sven Wischnowsky [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-02-12 15:45 Peter Stephenson
1999-02-12 17:33 ` Bart Schaefer
1999-02-13  7:05   ` PATCH: " Bart Schaefer

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=199902181105.MAA07404@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).