From 365c877d8b31653e12c5284266753671d6515774 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 24 Aug 2020 07:21:19 -0700 Subject: ffi: correct tft->nmemb under zero-bit fields. * ffi.c (make_ffi_type_struct, make_ffi_type_union): Assign tft->memb = memb after the loop which compiles the member types, because memb is decremented in the case of the zero-width bitfield. This hasn't cause an issue because the extra members are all zero, so their slot symbol is nil, and all the relevant operations skip a nil named member. --- ffi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ffi.c') diff --git a/ffi.c b/ffi.c index a0f58e9b..dd2fe20d 100644 --- a/ffi.c +++ b/ffi.c @@ -3260,7 +3260,6 @@ static val make_ffi_type_struct(val syntax, val lisp_type, tft->alloc = ffi_fixed_alloc; tft->dynsize = ffi_fixed_dynsize; tft->free = free; - tft->memb = memb; tft->incomplete = 1; @@ -3351,6 +3350,8 @@ static val make_ffi_type_struct(val syntax, val lisp_type, tft->by_value_in = 1; } + tft->memb = memb; + if (bit_offs > 0) { bug_unless (bit_offs < 8); offs++; @@ -3429,7 +3430,6 @@ static val make_ffi_type_union(val syntax, val use_existing, val self) tft->alloc = ffi_fixed_alloc; tft->dynsize = ffi_fixed_dynsize; tft->free = free; - tft->memb = memb; tft->incomplete = 1; @@ -3477,6 +3477,8 @@ static val make_ffi_type_union(val syntax, val use_existing, val self) } } + tft->memb = memb; + if (flexp) uw_throwf(error_s, lit("~a: unions cannot contain incomplete member"), -- cgit v1.2.3