Skip to content

girepository: Don't assume a bitfield has a fixed size

Adam Sampson requested to merge atsampson/glib:girepository-bitfield into main

The type used when declaring a bitfield member of a struct doesn't affect the amount of space allocated for it - only whether it's signed or unsigned. In standard C99 (6.2.7.1), only _Bool, signed int and unsigned int or typedefs to them are allowed as bitfield types, but GCC allows other integer types as an extension.

In this case, the GIBaseInfo and GIBaseInfoStack structs are meant to have identical layout. However, type_is_embedded was declared as an unsigned bitfield in the former and a uint32_t in the latter. This was harmless on most platforms because the following member is an aligned pointer, but (for example) on m68k-linux-gnu pointers only need to be 16-bit aligned, so GCC only allocates 16 bits for the bitfield.

Change the type in the declaration to unsigned int, and add an unnamed bitfield following it to ensure there's space for 32 bits on all platforms in the future.

Fixes #3355 (closed). I've tested this on m68k, x86_64, i686, aarch64, arm EABI and riscv64.

Merge request reports