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

Re: PATCH: Add :^ syntax for zipping two arrays



On Fri, 01 Aug 2014 16:46:57 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> I modeled it loosely on the :| / :* code which is just below it, which
> uses mkarray, zhalloc and dupstring, which is... confusing.

That'll be one of them bug things people sometimes try to interest me
in.

pws

diff --git a/Src/subst.c b/Src/subst.c
index 4713502..d6be2f0 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2935,7 +2935,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags)
 	     */
 	    if (!vunset) {
 		if (isarr) {
-		    aval = mkarray(NULL);
+		    aval = hmkarray(NULL);
 		} else {
 		    val = dupstring("");
 		}
diff --git a/Src/utils.c b/Src/utils.c
index aa978e6..998e46a 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3372,6 +3372,17 @@ mkarray(char *s)
 }
 
 /**/
+mod_export char **
+hmkarray(char *s)
+{
+    char **t = (char **) zhalloc((s) ? (2 * sizeof s) : (sizeof s));
+
+    if ((*t = s))
+	t[1] = NULL;
+    return t;
+}
+
+/**/
 mod_export void
 zbeep(void)
 {



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