From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24564 invoked by alias); 6 Sep 2014 21:48:19 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33118 Received: (qmail 28389 invoked from network); 6 Sep 2014 21:48:07 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140906144541.ZM18249@torch.brasslantern.com> Date: Sat, 06 Sep 2014 14:45:41 -0700 In-reply-to: <140906123433.ZM20433@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: set -o nounset; foo=(); print ${foo:#bar}" (Sep 6, 12:34pm) References: <20140906184749.GR4075@isis.sigpipe.cz> <140906123433.ZM20433@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: [PATCH] Re: set -o nounset; foo=(); print ${foo:#bar} MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Sep 6, 12:34pm, Bart Schaefer wrote: } Subject: Re: set -o nounset; foo=(); print ${foo:#bar} } } On Sep 6, 8:47pm, Roman Neuhauser wrote: } } } } roman@wrench ~ 0 1078 0 > print ${foo:#bar} } } zsh: foo: parameter not set } } roman@wrench ~ 0 1079 1 > } } } } the problematic part is ${foo:#bar} triggering nounset. FMPOV it *is* } } set (but null), so i'd say the observed behavior is a bug. } } This seems to be ${name:#word} being confused with ${name:?word} where } the ":" means to treat an empty parameter as unset. This also affects } the newer ${name:^word} form. I believe this fixes it; all tests still pass including the NOUNSET tests on ${array1:^array2}. diff --git a/Src/subst.c b/Src/subst.c index 4a5fe3a..1aa9b98 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1522,6 +1522,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) * unset. I don't quite understand why (v == NULL) isn't * good enough, but there are places where we seem to need * to second guess whether a value is a real value or not. + * See in particular the (colf && !vunset) test below. */ int vunset = 0; /* @@ -2638,8 +2639,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) * - (array) contains no elements * - (scalar) contains an empty string */ - if (colf && !vunset) + if (colf && !vunset) { vunset = (isarr) ? !*aval : !*val || (*val == Nularg && !val[1]); + vunset *= -1; /* Record that vunset was originally false */ + } switch (s[-1]) { case '+': @@ -2862,7 +2865,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) getmatcharr(&aval, s, flags, flnum, replstr); } else { if (vunset) { - if (unset(UNSET)) { + if (vunset > 0 && unset(UNSET)) { *idend = '\0'; zerr("%s: parameter not set", idbeg); return NULL; @@ -2892,7 +2895,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) return NULL; } if (vunset) { - if (unset(UNSET)) { + if (vunset > 0 && unset(UNSET)) { *idend = '\0'; zerr("%s: parameter not set", idbeg); return NULL; @@ -2974,7 +2977,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) *ap = NULL; } else { if (vunset) { - if (unset(UNSET)) { + if (vunset > 0 && unset(UNSET)) { *idend = '\0'; zerr("%s: parameter not set", idbeg); deletehashtable(ht); @@ -3003,7 +3006,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) } } if (vunset) { - if (unset(UNSET)) { + if (vunset > 0 && unset(UNSET)) { *idend = '\0'; zerr("%s: parameter not set", idbeg); return NULL; @@ -3020,7 +3023,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) val = dupstring(vunset ? "0" : "1"); isarr = 0; } else if (vunset) { - if (unset(UNSET)) { + if (vunset > 0 && unset(UNSET)) { *idend = '\0'; zerr("%s: parameter not set", idbeg); return NULL;