Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: Possible bug with ${(A)foo=} and ${(AA)foo=}



On Jun 23, 12:02pm, Peter Stephenson wrote:
} Subject: Re: Possible bug with ${(A)foo=} and ${(AA)foo=}
}
} Without fixing the general array-splitting problem, which is difficult, I
} don't see there's any problem deciding what to do in the case of an
} associative array, since the intention in such a case can only be to create
} an empty one because there is no key/value pair, even with ${(AA)foo=''}

OK, then ... here's a companion patch which defers allocation of the hash
table when there's nothing to put into it.

Index: Src/params.c
===================================================================
@@ -1898,7 +1898,7 @@
      * since that could cause trouble for special hashes.  This way, *
      * it's up to pm->sets.hfn() what to do.                         */
     int alen = arrlen(val);
-    HashTable opmtab = paramtab, ht;
+    HashTable opmtab = paramtab, ht = 0;
     char **aptr = val;
     Value v = (Value) hcalloc(sizeof *v);
     v->b = -1;
@@ -1909,7 +1909,8 @@
 	     NULL, 0);
 	return;
     }
-    ht = paramtab = newparamtable(17, pm->nam);
+    if (alen)
+	ht = paramtab = newparamtable(17, pm->nam);
     while (*aptr) {
 	/* The parameter name is ztrdup'd... */
 	v->pm = createparam(*aptr, PM_SCALAR|PM_UNSET);

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author