From c496a924ce71317aa5560da0cbf5a4524bb8c226 Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Wed, 15 May 2013 00:22:44 +0100 Subject: Bugfix for array slices. --- jv_aux.c | 3 +++ tests/all.test | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/jv_aux.c b/jv_aux.c index 28755644..68811cd0 100644 --- a/jv_aux.c +++ b/jv_aux.c @@ -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] -- cgit v1.2.3