Commit e7927faf authored by Allison Karlitskaya's avatar Allison Karlitskaya

GVariant: One more FreeBSD fix

FreeBSD's malloc() sometimes returns unaligned memory if you are
requesting small sizes.  This can get GVariant into trouble.  For
example, consider the type "mmi" containing the value "just nothing".
According to the type signature, the memory containing this should be
aligned to a boundary of 4 since it might contain an int.  The
serialised size of this value is 1 byte, however, and when you ask
FreeBSD to allocate memory of that size, it knows you can't put an int
into it so it doesn't bother aligning it.

This patch modifies the GVariant serialiser to not assert the alignment
constraint in the case that the size of the serialised data is smaller
than its own alignment requirement.
parent 271997de
......@@ -129,7 +129,7 @@ static void
g_variant_serialised_check (GVariantSerialised serialised)
gsize fixed_size;
guint alignment;
gsize alignment;
g_assert (serialised.type_info != NULL);
g_variant_type_info_query (serialised.type_info, &alignment, &fixed_size);
......@@ -157,6 +157,16 @@ g_variant_serialised_check (GVariantSerialised serialised)
) - 9;
/* Some OSes (FreeBSD is a known example) have a malloc() that returns
* unaligned memory if you request small sizes. 'malloc (1);', for
* example, has been seen to return pointers aligned to 6 mod 16.
* Check if this is a small allocation and return without enforcing
* the alignment assertion if this is the case.
if (serialised.size <= alignment)
g_assert_cmpint (alignment & (gsize), ==, 0);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment