about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-09-06 15:28:17 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-09-06 15:28:17 +0000
commitf2d873d8114561c4c8658659408d9cecfe60a0fc (patch)
tree31360e794f27687dd30dc2e6e1a0dda8e8aaafd6
parent394ab0aeb72190e66aca3b3d21c9d3264fe1129f (diff)
downloadzsh-f2d873d8114561c4c8658659408d9cecfe60a0fc.tar.gz
zsh-f2d873d8114561c4c8658659408d9cecfe60a0fc.tar.xz
zsh-f2d873d8114561c4c8658659408d9cecfe60a0fc.zip
21701: Negative subscripts of scalars before start were broken
-rw-r--r--ChangeLog5
-rw-r--r--Src/params.c5
-rw-r--r--Test/D06subscript.ztst5
3 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index ad5d5a0fd..e2f42c912 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-09-06  Peter Stephenson  <pws@csr.com>
+
+	* 21701: Src/params.c, Test/D06subscript.ztst: negative offsets
+	that indexed before the start of a scalar weren't handled properly.
+
 2005-09-05  Peter Stephenson  <pws@csr.com>
 
 	* 21698: Jean-Baptiste Quenot: Completion/Unix/Command/_ant:
diff --git a/Src/params.c b/Src/params.c
index 26b3f3133..1cff358df 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1565,8 +1565,11 @@ getstrvalue(Value v)
     if (v->start == 0 && v->end == -1)
 	return s;
 
-    if (v->start < 0)
+    if (v->start < 0) {
 	v->start += strlen(s);
+	if (v->start < 0)
+	    v->start = 0;
+    }
     if (v->end < 0)
 	v->end += strlen(s) + 1;
     s = (v->start > (int)strlen(s)) ? dupstring("") : dupstring(s + v->start);
diff --git a/Test/D06subscript.ztst b/Test/D06subscript.ztst
index f90c1cb0a..9ce022557 100644
--- a/Test/D06subscript.ztst
+++ b/Test/D06subscript.ztst
@@ -178,3 +178,8 @@
 0:Keys with double quotes and the (P) expansion flag
 >lower
 >upper
+
+  typeset -a empty_array
+  echo X${${l##*}[-1]}X
+0:Negative index applied to substition result from empty array
+>XX