Automatically realign data passed to g_variant_new_from_bytes() or g_variant_new_from_data()
@pwithnall
Submitted by Philip Withnall Link to original bug (#793394)
Description
If a byte array which is passed to g_variant_new_from_bytes|data is not sufficiently aligned for the given GVariantType, a critical warning will be emitted:
gvariant-serialiser.c:167:g_variant_serialised_check: assertion failed (alignment & (gsize) serialised.data == 0): (4 == 0)
The caller can’t know what alignment the GVariantType is meant to have (it’s not exposed in public API) — and even if they were, making every caller of g_variant_new_from_bytes|data realign their data amounts to a lot of code.
It would be better if the realignment was done (only if needed) in gvariant-core.c, and documented. If callers care about speed, they can ensure their byte arrays are correctly aligned before passing them to GVariant.
This also means we can eliminate the align_malloc() faff in glib/tests/gvariant.c, and partially revert commit 7b607082.
Version: 2.55.x