From ed73979d131383a082efa7d6e588ffe47464bb89 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 13 Jun 2017 19:08:22 -0700 Subject: ffi: fix buggy bitfield allocation. * ffi.c (make_ffi_type_struct): When there is no room in the current bitfield, two mistakes are made. When bit_offs is reset to zero in this case, the dependent variable bits_alloc that was calculated from it (bits allocated to current unit) must also be reset. The subsequent shift depends on it. Secondly, when we establish the memb[i].offs field, that must come from offs, not from unit_offs, because unit_offs is always the base offset of the existing cell (which doesn't have room for the new bitfield in this case); the main offset variable offs is what gets gets adjusted to the cell which has room for the new bitfield. --- ffi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ffi.c') diff --git a/ffi.c b/ffi.c index beef8d1e..8776aad4 100644 --- a/ffi.c +++ b/ffi.c @@ -2796,7 +2796,7 @@ static val make_ffi_type_struct(val syntax, val lisp_type, if (bits > room) { offs = unit_offs + size; - bit_offs = 0; + bit_offs = bits_alloc = 0; } if (bits_alloc == 0) { @@ -2804,7 +2804,7 @@ static val make_ffi_type_struct(val syntax, val lisp_type, most_align = mtft->align; } - memb[i].offs = unit_offs; + memb[i].offs = offs; #if HAVE_LITTLE_ENDIAN mtft->shift = bits_alloc; -- cgit v1.2.3