From 1acf23db3eceaae559328db68d6aae755edb0fb8 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sat, 5 Sep 2009 19:49:19 +0000 Subject: 27243: reverse indexing of arrays with beginning index out of range returned wrong value --- ChangeLog | 8 +++++++- Src/params.c | 10 ++++++++++ Test/D04parameter.ztst | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8ecc79fe9..32bf838bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-09-05 Peter Stephenson + + * 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 * 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 -- cgit 1.4.1