summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-10 22:06:19 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-10 22:06:19 -0700
commita8d124d7626602c6ff44c63757d3c56e6392fc80 (patch)
treef8708a67b16a67d0d2a6952f3fdbd5eb14440879 /ffi.c
parente08221a2b9c0286d9c6bed73be61516ee44e3b64 (diff)
downloadtxr-a8d124d7626602c6ff44c63757d3c56e6392fc80.tar.gz
txr-a8d124d7626602c6ff44c63757d3c56e6392fc80.tar.bz2
txr-a8d124d7626602c6ff44c63757d3c56e6392fc80.zip
ffi: bugfix: wrong type in allocation of varrays.
* ffi.c (ffi_varray_alloc): We must use the element type's size, not the array's size. Also, cosmetic issue in error message fixed.
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ffi.c b/ffi.c
index cedf5934..e9592886 100644
--- a/ffi.c
+++ b/ffi.c
@@ -244,9 +244,11 @@ static mem_t *ffi_fixed_alloc(struct txr_ffi_type *tft, val obj, val self)
static mem_t *ffi_varray_alloc(struct txr_ffi_type *tft, val obj, val self)
{
ucnum len = c_unum(length(obj));
- size_t size = tft->size * len;
+ val eltype = tft->mtypes;
+ struct txr_ffi_type *etft = ffi_type_struct(eltype);
+ size_t size = etft->size * len;
if (size < len || size < tft->size)
- uw_throwf(error_s, lit("~s: array size overflow"), self, nao);
+ uw_throwf(error_s, lit("~a: array size overflow"), self, nao);
return chk_malloc(size);
}