summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-10-07 12:42:55 -0700
committerKaz Kylheku <kaz@kylheku.com>2024-10-07 12:42:55 -0700
commite915fbeba8c16a6b0dcb84a8f34c25db3aeaec13 (patch)
tree4d5b8f4c2f8dbca2fd3bb71e6795af3662ed1b2c
parentef9740c6cb9d7f6dbccaedd1694fc4726f9a0b6e (diff)
downloadtxr-e915fbeba8c16a6b0dcb84a8f34c25db3aeaec13.tar.gz
txr-e915fbeba8c16a6b0dcb84a8f34c25db3aeaec13.tar.bz2
txr-e915fbeba8c16a6b0dcb84a8f34c25db3aeaec13.zip
ffi: bug: flexible structure size calculation.
* ffi.c (make_ffi_type_struct): We must calculate the size of a flexible structure the way GCC does it. We cannot simply truncate it at the offset of the member. Rather, the size is calculated in the usual way. The alignment of the array is taken into account for the purpose of determining what is the most aligned member of the structure, and then padding is added, if required. Thus, the size may exceed the offset of that member.
-rw-r--r--ffi.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/ffi.c b/ffi.c
index acea5db0..91845e67 100644
--- a/ffi.c
+++ b/ffi.c
@@ -3916,13 +3916,12 @@ static val make_ffi_type_struct(val syntax, val lisp_type,
tft->out = ffi_struct_out;
if (flexp) {
- tft->size = offs;
tft->alloc = ffi_flex_alloc;
tft->dynsize = ffi_flex_dynsize;
- } else {
- tft->size = (offs + most_align - 1) & ~(most_align - 1);
}
+ tft->size = (offs + most_align - 1) & ~(most_align - 1);
+
tft->align = most_align;
return obj;