summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-09-05 19:49:19 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-09-05 19:49:19 +0000
commit1acf23db3eceaae559328db68d6aae755edb0fb8 (patch)
tree38e42f719e3a3671d1850023ecc5e13d7a40ee41
parent6d4d1261a5c813033f01e90c708c0dcfbc7e1b6e (diff)
downloadzsh-1acf23db3eceaae559328db68d6aae755edb0fb8.tar.gz
zsh-1acf23db3eceaae559328db68d6aae755edb0fb8.tar.xz
zsh-1acf23db3eceaae559328db68d6aae755edb0fb8.zip
27243: reverse indexing of arrays with beginning index out of range returned
wrong value
-rw-r--r--ChangeLog8
-rw-r--r--Src/params.c10
-rw-r--r--Test/D04parameter.ztst28
3 files changed, 45 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 8ecc79fe9..32bf838bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-09-05  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 27243: Src/params.c, Test/D04parameter.ztst: reverse
+	indexing in array parameters with a beginning index out of range
+	returned the wrong value.
+
 2009-09-02  Peter Stephenson  <pws@csr.com>
 
 	* 27240: Src/builtin.c: 27079 caused later use of tokstr and tok
@@ -12111,5 +12117,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4766 $
+* $Revision: 1.4767 $
 *****************************************************
diff --git a/Src/params.c b/Src/params.c
index 4767aaa34..0425e0700 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1345,6 +1345,11 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
 	    len = arrlen(ta);
 	    if (beg < 0)
 		beg += len;
+	    if (down) {
+		if (beg < 0)
+		    return 0;
+	    } else if (beg >= len)
+		return len + 1;
 	    if (beg >= 0 && beg < len) {
 		if (down) {
 		    if (!hasbeg)
@@ -1363,6 +1368,11 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
 	    len = arrlen(ta);
 	    if (beg < 0)
 		beg += len;
+	    if (down) {
+		if (beg < 0)
+		    return 0;
+	    } else if (beg >= len)
+		return len + 1;
 	    if (beg >= 0 && beg < len) {
 		if (down) {
 		    if (!hasbeg)
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 358b46ef7..59fa3ac91 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -998,6 +998,34 @@
 >sunny
 >day
 
+# ' emacs likes this close quote
+
+  a=(sping spang spong bumble)
+  print ${a[(i)spong]}
+  print ${a[(i)spung]}
+  print ${a[(ib.1.)spong]}
+  print ${a[(ib.4.)spong]}
+  print ${a[(ib.10.)spong]}
+0:In and out of range reverse matched indices without and with b: arrays
+>3
+>5
+>3
+>5
+>5
+
+  a="thrimblewuddlefrong"
+  print ${a[(i)w]}
+  print ${a[(i)x]}
+  print ${a[(ib.3.)w]}
+  print ${a[(ib.10.)w]}
+  print ${a[(ib.30.)w]}
+0:In and out of range reverse matched indices without and with b: strings
+>9
+>20
+>9
+>20
+>20
+
   foo="line:with::missing::fields:in:it"
   print -l ${(s.:.)foo}
 0:Removal of empty fields in unquoted splitting