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

Re: segfault in 4.1.1-test-2 with ${(u)${=:-$(echo yes yes)}}



I could add comments about this, but why start now?  The whole of
paramsubst() needs to be something else entirely.

I *hate* that function.

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.32
diff -u -r1.32 subst.c
--- Src/subst.c	7 May 2003 09:38:53 -0000	1.32
+++ Src/subst.c	21 May 2003 15:59:49 -0000
@@ -1951,24 +1951,31 @@
 	int i;
 	LinkNode on = n;
 
-	if (!aval[0] && !plan9) {
+	if (unique) {
+	    if(!copied)
+		aval = arrdup(aval);
+
+	    i = arrlen(aval);
+	    if (i > 1)
+		zhuniqarray(aval);
+	}
+	if ((!aval[0] || !aval[1]) && !plan9) {
+	    int vallen;
 	    if (aptr > (char *) getdata(n) &&
 		aptr[-1] == Dnull && *fstr == Dnull)
 		*--aptr = '\0', fstr++;
-	    y = (char *) hcalloc((aptr - ostr) + strlen(fstr) + 1);
+	    vallen = aval[0] ? strlen(aval[0]) : 0;
+	    y = (char *) hcalloc((aptr - ostr) + vallen + strlen(fstr) + 1);
 	    strcpy(y, ostr);
 	    *str = y + (aptr - ostr);
+	    if (vallen)
+	    {
+		strcpy(*str, aval[0]);
+		*str += vallen;
+	    }
 	    strcpy(*str, fstr);
 	    setdata(n, y);
 	    return n;
-	}
-	if (unique) {
-	    if(!copied)
-		aval = arrdup(aval);
-
-	    i = arrlen(aval);
-	    if (i > 1)
-		zhuniqarray(aval);
 	}
 	if (sortit) {
 	    if (!copied)
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.8
diff -u -r1.8 D04parameter.ztst
--- Test/D04parameter.ztst	7 May 2003 09:38:53 -0000	1.8
+++ Test/D04parameter.ztst	21 May 2003 15:59:49 -0000
@@ -589,3 +589,13 @@
 0:Parameters associated with (#m) flag
 >MATCH 16 20 MATCH
 >5
+
+  print -l JAMES${(u)${=:-$(echo yes yes)}}JOYCE
+  print -l JAMES${(u)${=:-$(echo yes yes she said yes i will yes)}}JOYCE
+0:Bug with (u) flag reducing arrays to one element
+>JAMESyesJOYCE
+>JAMESyes
+>she
+>said
+>i
+>willJOYCE

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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