summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-06-27 06:03:04 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-06-27 06:03:04 -0700
commit3dd72471c9898f8dcc56b81ec0f1f531010d3306 (patch)
tree50ac8384950deaadb162f5956acd28685471093c
parent9e9745fa7dfc111a8b1efcdfe5f1c09aeca06605 (diff)
downloadtxr-3dd72471c9898f8dcc56b81ec0f1f531010d3306.tar.gz
txr-3dd72471c9898f8dcc56b81ec0f1f531010d3306.tar.bz2
txr-3dd72471c9898f8dcc56b81ec0f1f531010d3306.zip
ffi: fix incorrect null-terminated array in op.
* ffi.c (ffi_varray_null_term_in): Rewrite nonsensical code that refers to the newly created empty output array as input. We must perform the in semantics on all the original elements. Then get semantics on any new elements if the array was extended, and the copy flag is true (by-ref nuance).
-rw-r--r--ffi.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ffi.c b/ffi.c
index 049c16d1..0d531724 100644
--- a/ffi.c
+++ b/ffi.c
@@ -2522,6 +2522,7 @@ static val ffi_varray_null_term_in(struct txr_ffi_type *tft, int copy, mem_t *sr
struct txr_ffi_type *etft = ffi_type_struct(eltype);
cnum elsize = etft->size;
cnum offs, i;
+ cnum nelem_orig = c_num(length(vec_in));
for (i = 0, offs = 0; ; i++) {
mem_t *el = src + offs, *p;
@@ -2533,9 +2534,9 @@ static val ffi_varray_null_term_in(struct txr_ffi_type *tft, int copy, mem_t *sr
if (p == el + elsize)
break;
- if (etft->in != 0) {
- val elval = ref(vec, num_fast(i));
- vec_push(vec, elval);
+ if (etft->in != 0 && i < nelem_orig) {
+ val elval = ref(vec_in, num_fast(i));
+ vec_push(vec, etft->in(etft, copy, src + offs, elval, self));
} else if (copy) {
val elval = etft->get(etft, src + offs, self);
vec_push(vec, elval);