From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18291 invoked by alias); 31 Aug 2015 13:19:35 -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: 36347 Received: (qmail 24210 invoked from network); 31 Aug 2015 13:19:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=T3znBlRrdVRRFUbeG1MSA9Jxd14aPXe/ad0MCD90T2w=; b=GQjBStQ0hqBylvr/w9JIReH5HNc2hSON+qRLw1M0ZirV7ffrYqM2NcVDgdIw4510sE lEZsZycAtSOplNCwxHJAw9ziqNpNrROd4TADjLaAOPNr7CnAszoHyZh+ddFTTAt54QfY VygXR3e1YfVysxUDTh3VBGuwsRluMU5eXC7R1j+Etr+GloQndZz2MBKrfd0NQwM95ud2 QgCnqlZDEmo1yDmESK7C2f6+FbjbzUgJ2Lz2V7NRyopx2LgoY5Dc5WfFnmYdGMI0o0TL L+9Dd7acjwBOHtM/tqhpgqLJQy5ZEry6BI8ki1WZ34YRChdqRWrzhAZM0bb9RydZoHt0 HJkw== X-Received: by 10.180.80.138 with SMTP id r10mr19305834wix.18.1441027163330; Mon, 31 Aug 2015 06:19:23 -0700 (PDT) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Fix appending empty array to associations Date: Mon, 31 Aug 2015 15:19:17 +0200 Message-Id: <1441027157-30623-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 2.5.0 I discovered that % typeset -A foo=(a 1) % foo+=() results in foo being emptied, which surprised me. Daniel Shahaf tracked down the code in question and figured out removing the original "if (alen)" line appeared to fix it. This patch attempts to be more similar to the previous code in the case that we are not appending (which is called augmenting in the code but nowhere in the documentation, okay). I also took the opportunity to reword the very confusing golfed statement into something you can follow somewhat easily. I haven't run into any problems so far, but it might be worth giving this a second look. --- Src/params.c | 9 ++++++--- Test/A06assign.ztst | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Src/params.c b/Src/params.c index c8b4356..e7c2ce7 100644 --- a/Src/params.c +++ b/Src/params.c @@ -3315,9 +3315,12 @@ arrhashsetfn(Param pm, char **val, int augment) zerr("bad set of key/value pairs for associative array"); return; } - if (alen) - if (!(augment && (ht = paramtab = pm->gsu.h->getfn(pm)))) - ht = paramtab = newparamtable(17, pm->node.nam); + if (augment) { + ht = paramtab = pm->gsu.h->getfn(pm); + } + if (alen && (!augment || !paramtab)) { + ht = paramtab = newparamtable(17, pm->node.nam); + } while (*aptr) { /* The parameter name is ztrdup'd... */ v->pm = createparam(*aptr, PM_SCALAR|PM_UNSET); diff --git a/Test/A06assign.ztst b/Test/A06assign.ztst index 302659c..1e3d2ed 100644 --- a/Test/A06assign.ztst +++ b/Test/A06assign.ztst @@ -249,6 +249,14 @@ >2 >3 + typeset -A h + h=(a 1 b 2) + h+=() + print -l $h +0:add empty array to association +>1 +>2 + # tests of var[range]+=scalar s=sting -- 2.5.0