diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-10-26 19:58:11 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-10-26 19:58:11 -0700 |
commit | 465cae2b99c6ded5bebdf71d151941832e718672 (patch) | |
tree | 2ff1f94b35fdde71d5f3137804dcc3d699549dd2 | |
parent | a64bc1ebccbbe22890fccc09d44d2f199775f80d (diff) | |
download | txr-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.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -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); |