From 6dfc706e972b6f2c0f701ab896afe60d262619da Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 19 May 2017 20:42:07 -0700 Subject: ffi: incomplete types can't be aggregate elements. Ban types like (struct foo (bar void)) or (array 3 (array int)). * ffi.c (ffi_struct_compile): Check every element type for zero size and diagnose. (ffi_type_compile): Likewise, for arrays. --- ffi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ffi.c b/ffi.c index ce97c2e4..c916ad8f 100644 --- a/ffi.c +++ b/ffi.c @@ -1541,9 +1541,14 @@ static val ffi_struct_compile(val membs, val *ptypes, val self) val mp = car(membs); val name = car(mp); val type = cadr(mp); + val comp_type = ffi_type_compile(type); + struct txr_ffi_type *ctft = ffi_type_struct(comp_type); if (cddr(mp)) uw_throwf(error_s, lit("~a: excess elements in type-member pair ~s"), self, mp, nao); + if (ctft->size == 0) + uw_throwf(error_s, lit("~a: incomplete type ~s cannot be struct member"), + self, type, nao); pttail = list_collect(pttail, ffi_type_compile(type)); pstail = list_collect(pstail, name); } @@ -1581,6 +1586,11 @@ val ffi_type_compile(val syntax) ffi_varray_in, 0, ffi_varray_release, eltype); struct txr_ffi_type *tft = ffi_type_struct(type); + struct txr_ffi_type *etft = ffi_type_struct(eltype); + if (etft->size == 0) + uw_throwf(error_s, + lit("~a: incomplete type ~s cannot be array element"), + self, eltype_syntax, nao); if (sym == zarray_s) tft->null_term = 1; tft->alloc = ffi_varray_alloc; @@ -1591,6 +1601,12 @@ val ffi_type_compile(val syntax) val dim = cadr(syntax); val eltype_syntax = caddr(syntax); val eltype = ffi_type_compile(eltype_syntax); + struct txr_ffi_type *etft = ffi_type_struct(eltype); + + if (etft->size == 0) + uw_throwf(error_s, + lit("~a: incomplete type ~s cannot be array element"), + self, eltype_syntax, nao); if (minusp(dim)) uw_throwf(error_s, lit("~a: negative dimension in ~s"), -- cgit v1.2.3