diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-05-19 07:20:14 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-05-19 07:20:14 -0700 |
commit | dd390a2cb27cea56a9e7654dede6fcda57e8ff09 (patch) | |
tree | 9c24447d574b5fcf1a1b73bbec850033310b9b24 /ffi.c | |
parent | 100453d6f78a232b6666c93c6abd9e55a531d953 (diff) | |
download | txr-dd390a2cb27cea56a9e7654dede6fcda57e8ff09.tar.gz txr-dd390a2cb27cea56a9e7654dede6fcda57e8ff09.tar.bz2 txr-dd390a2cb27cea56a9e7654dede6fcda57e8ff09.zip |
ffi: diagnose bitfields wider than type.
* ffi.c (ffi_type_compile): Show the original bitfield syntax
in the invalid size diagnostics. In the case of the (bit n type)
syntax, restrict the maximum bits to the width of the type,
not just to 32 or 64. I realize the 8 * tft->size calculation
can overflow for huge array types, but it makes no sense to use
them as bitfields.
Diffstat (limited to 'ffi.c')
-rw-r--r-- | ffi.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -4181,9 +4181,9 @@ val ffi_type_compile(val syntax) if (cddr(syntax)) goto excess; if (nb < 0 || nb > bits_int) - uw_throwf(error_s, lit("~a: invalid bitfield size ~s; " + uw_throwf(error_s, lit("~a: invalid bitfield size ~s in ~s: " "must be 0 to ~s"), - self, nbits, num_fast(bits_int), nao); + self, nbits, syntax, num_fast(bits_int), nao); tft->nelem = c_num(nbits, self); tft->bitfield = 1; if (nb == bits_int) @@ -4203,9 +4203,9 @@ val ffi_type_compile(val syntax) const int bits_int = 8 * sizeof(int); #if HAVE_I64 const int bits_llint = 8 * sizeof(u64_t); - const int bits_lim = bits_llint; + const int bits_lim = min(8 * tft->size, bits_llint); #else - const int bits_lim = bits_int; + const int bits_lim = min(8 * tft->size, bits_int); #endif val type_copy = ffi_type_copy(type); struct txr_ffi_type *tft_cp = ffi_type_struct(type_copy); @@ -4229,9 +4229,9 @@ val ffi_type_compile(val syntax) } if (nb < 0 || nb > bits_lim) - uw_throwf(error_s, lit("~a: invalid bitfield size ~s; " + uw_throwf(error_s, lit("~a: bitfield size ~s in ~s: " "must be 0 to ~s"), - self, nbits, num_fast(bits_lim), nao); + self, nbits, syntax, num_fast(bits_lim), nao); tft_cp->syntax = xsyntax; tft_cp->nelem = nb; |