summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-24 06:20:28 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-24 06:20:28 -0700
commit2262860404bad7755c6a8adb10f167439037f3fa (patch)
treed2c46acda2a935d4f835084b37bceec0be6cb3e0 /ffi.c
parent6357ea31bd2755d29a1643b71e15da5b8facc779 (diff)
downloadtxr-2262860404bad7755c6a8adb10f167439037f3fa.tar.gz
txr-2262860404bad7755c6a8adb10f167439037f3fa.tar.bz2
txr-2262860404bad7755c6a8adb10f167439037f3fa.zip
ffi: couple of tests; assertion.
* ffi.c (make_ffi_type_struct): Add check for impossible condition. The bits_alloc variable could only exceed bits_type (and thus cause the room variable to have a nonsensical, large value) if the bitfield allocation tried to continue allocating bits into an aligned unit, whose alignment exceeds the size of the underlying type. But in that case, tft->aligned would have to be true, and so the offset would have been aligned prior to this code, rendering bits_alloc zero. * tests/017/bitfields.tl: New tests.
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/ffi.c b/ffi.c
index 1c44b442..db7a4c38 100644
--- a/ffi.c
+++ b/ffi.c
@@ -3817,6 +3817,8 @@ static val make_ffi_type_struct(val syntax, val lisp_type,
ucnum bits_alloc = 8 * (offs - unit_offs) + bit_offs;
ucnum room = bits_type - bits_alloc;
+ bug_unless (bits_type >= bits_alloc);
+
if (bits == 0) {
ucnum szmask = size - 1;
ucnum unit_offs = offs & ~szmask;