summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-10-26 19:58:11 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-10-26 19:58:11 -0700
commit465cae2b99c6ded5bebdf71d151941832e718672 (patch)
tree2ff1f94b35fdde71d5f3137804dcc3d699549dd2
parenta64bc1ebccbbe22890fccc09d44d2f199775f80d (diff)
downloadtxr-465cae2b99c6ded5bebdf71d151941832e718672.tar.gz
txr-465cae2b99c6ded5bebdf71d151941832e718672.tar.bz2
txr-465cae2b99c6ded5bebdf71d151941832e718672.zip
carray: bugfix: allow negative indexing in ref operation.
* ffi.c (carray_ref): If the index is negative, displace it by the length of the array. (Then if it is still negative, the function will throw.)
-rw-r--r--ffi.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/ffi.c b/ffi.c
index 82a28b5b..67ced1f0 100644
--- a/ffi.c
+++ b/ffi.c
@@ -4888,6 +4888,9 @@ val carray_ref(val carray, val idx)
struct carray *scry = carray_struct_checked(carray);
cnum ix = c_num(idx);
+ if (ix < 0)
+ ix += scry->nelem;
+
if (ix < 0 || (scry->nelem >= 0 && ix >= scry->nelem)) {
uw_throwf(error_s, lit("~a: ~s: index ~s out of bounds"),
self, carray, idx, nao);