From fd1ab98af87e69055a7f5d42128f5a8bde6acf2c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 6 May 2017 23:54:16 -0700 Subject: ffi: bugfixes: out pointer must be checked. * ffi.c (ffi_closure_dispatch): Only call out on those arguments which have a non-null out pointer, otherwise we will crash. Those non-null values are the reason we even execute that loop at all. (ffi_out): Do a put for basic types (which have no out handler). --- ffi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ffi.c b/ffi.c index b693628b..49601339 100644 --- a/ffi.c +++ b/ffi.c @@ -1820,7 +1820,8 @@ static void ffi_closure_dispatch(ffi_cif *cif, void *cret, val type = pop(&types); val arg = args_at(args_cp, i); struct txr_ffi_type *mtft = ffi_type_struct(type); - mtft->out(mtft, 0, arg, convert(mem_t *, cargs[i]), self); + if (mtft->out != 0) + mtft->out(mtft, 0, arg, convert(mem_t *, cargs[i]), self); } } @@ -1931,7 +1932,10 @@ val ffi_out(val dstbuf, val obj, val type, val copy_p) if (lt(length_buf(dstbuf), num_fast(tft->size))) uw_throwf(lit("~a: buffer ~s is too small for type ~s"), self, dstbuf, type, nao); - tft->out(tft, copy_p != nil, obj, dst, self); + if (tft->out != 0) + tft->out(tft, copy_p != nil, obj, dst, self); + else + tft->put(tft, obj, dst, self); return dstbuf; } -- cgit v1.2.3