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

Re: using array slice as lvalue



On Dec 21,  3:42pm, Le Wang wrote:
}
} arr=(a b c)
} arr[2,-1]=(z)
} typeset arr # arr=(a z b c)

I would have to say that is a bug.  [1,-1] is handled as a special case,
but it appears assignment botches other negative indices unless both
the start and the end are negative.

Rather amazing that this has never come up before (and of course it
can't help but appear immediately after a release is announced).

Potential patch -- fixes this case and still passes "make check" but
may break some other obscure corner:

Index: Src/params.c
--- zsh-forge/current/Src/params.c	2010-11-19 09:49:19.000000000 -0800
+++ Src/params.c	2010-12-21 00:40:29.000000000 -0800
@@ -2442,8 +2442,6 @@
 		v->start--;
 	    v->end--;
 	}
-	if (v->end < v->start)
-	    v->end = v->start;
 	q = old = v->pm->gsu.a->getfn(v->pm);
 	n = arrlen(old);
 	if (v->start < 0) {
@@ -2456,6 +2454,8 @@
 	    if (v->end < 0)
 		v->end = 0;
 	}
+	if (v->end < v->start)
+	    v->end = v->start;
 
 	ll = v->start + arrlen(val);
 	if (v->end <= n)



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