zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Icky little array slice assignment bug
@ 2001-05-18 17:34 Bart Schaefer
  2001-05-18 18:16 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2001-05-18 17:34 UTC (permalink / raw)
  To: zsh-workers

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   


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-05-20 21:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-18 17:34 PATCH: Icky little array slice assignment bug Bart Schaefer
2001-05-18 18:16 ` Bart Schaefer
2001-05-19 12:13   ` Wayne Davison
2001-05-20  9:25     ` Wayne Davison
2001-05-20 21:31       ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).