summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-06-14 07:09:53 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-06-14 07:09:53 -0700
commit3d685d1985cd06cb0bcbb53cca66ab3239f4ea06 (patch)
tree82c8320650752cfe40f1fbdeba93dc004b6c9991
parent0ca6b880539ca0ebd2faa784e0bab9a928a91332 (diff)
downloadtxr-3d685d1985cd06cb0bcbb53cca66ab3239f4ea06.tar.gz
txr-3d685d1985cd06cb0bcbb53cca66ab3239f4ea06.tar.bz2
txr-3d685d1985cd06cb0bcbb53cca66ab3239f4ea06.zip
carray-refset: bugfix: support negative indexing.
* ffi.c (carray_refset): Support negative indexing by adding the length of the array to a negative index value. This is already done in carray_ref.
-rw-r--r--ffi.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/ffi.c b/ffi.c
index e2900d4d..2459dc17 100644
--- a/ffi.c
+++ b/ffi.c
@@ -4829,6 +4829,9 @@ val carray_refset(val carray, val idx, val newval)
struct carray *scry = carray_struct_checked(self, 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);