Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Icky little array slice assignment bug
- X-seq: zsh-workers 14386
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: Icky little array slice assignment bug
- Date: Fri, 18 May 2001 17:34:38 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
This appears to date back about a year, roughly to Wayne's change to use
zero-based indexing internally on array subscripts (zsh-workers/11677).
zagzig% a=(x y z)
zagzig% echo $a[(i)q]
4
zagzig% echo $a[(I)q]
0
zagzig% a[(I)q]=W
zagzig% echo $a
x y W x y z
The following patch fixes it, though I'm not sure it's the best way.
There remains this bug of extremely long standing:
zagzig% a[(r)q]=V
zagzig% echo $a
x y W x y z V <-- this is ok
zagzig% a[(R)q]=U
zagzig% echo $a
U y W x y z V <-- this is probably unexpected
That is, there's a phantom element at the right end of an array but not at
the left, so you can "push" but not "unshift" elements -- an attempt to
insert at the beginning of the array clobbers the first element. We could
special-case an assignment to index zero when ksharrays is not in effect,
but it might be a bit messy.
Index: Src/params.c
===================================================================
--- Src/params.c 2001/05/02 16:59:02 1.6
+++ Src/params.c 2001/05/18 17:13:17
@@ -1721,7 +1721,7 @@
v->pm->nam, 0);
return;
}
- if (v->inv && unset(KSHARRAYS))
+ if (v->inv && unset(KSHARRAYS) && v->start > 0)
v->start--, v->end--;
q = old = v->pm->gets.afn(v->pm);
n = arrlen(old);
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author