diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-05-15 00:22:44 +0100 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-05-15 00:22:44 +0100 |
commit | c496a924ce71317aa5560da0cbf5a4524bb8c226 (patch) | |
tree | 1144c05d96cb7c014bf31501de10a19c31b69e85 | |
parent | 81be37b23601a948164f0eb4a4f0331fa83ccf15 (diff) |
Bugfix for array slices.
-rw-r--r-- | jv_aux.c | 3 | ||||
-rw-r--r-- | tests/all.test | 4 |
2 files changed, 5 insertions, 2 deletions
@@ -26,9 +26,12 @@ static int parse_slice(jv array, jv slice, int* pstart, int* pend) { int end = (int)jv_number_value(end_jv); if (start < 0) start = len + start; if (end < 0) end = len + end; + if (start < 0) start = 0; + if (start > len) start = len; if (end > len) end = len; if (end < start) end = start; + assert(0 <= start && start <= end && end <= len); *pstart = start; *pend = end; return 1; diff --git a/tests/all.test b/tests/all.test index 4eaa9b61..0119dad6 100644 --- a/tests/all.test +++ b/tests/all.test @@ -170,9 +170,9 @@ null # Slices # -[.[3:2], .[-5:4], .[:-2], .[-2:]] +[.[3:2], .[-5:4], .[:-2], .[-2:], .[3:3][1:], .[10:]] [0,1,2,3,4,5,6] -[[], [2,3], [0,1,2,3,4], [5,6]] +[[], [2,3], [0,1,2,3,4], [5,6], [], []] del(.[2:4],.[0],.[-2:]) [0,1,2,3,4,5,6,7] |