diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-05-06 23:54:16 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-05-06 23:54:16 -0700 |
commit | fd1ab98af87e69055a7f5d42128f5a8bde6acf2c (patch) | |
tree | ae3fa39e8b02272f665baf09a58df07650c7327b | |
parent | baffee5455676a7359f755689421d4c00f5fc4c1 (diff) | |
download | txr-fd1ab98af87e69055a7f5d42128f5a8bde6acf2c.tar.gz txr-fd1ab98af87e69055a7f5d42128f5a8bde6acf2c.tar.bz2 txr-fd1ab98af87e69055a7f5d42128f5a8bde6acf2c.zip |
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).
-rw-r--r-- | ffi.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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; } |