[glib] GVariant: One more FreeBSD fix
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GVariant: One more FreeBSD fix
- Date: Thu, 27 May 2010 15:36:29 +0000 (UTC)
commit e7927faf1792ad4c3c8a5b599240a7ee94b1a0cc
Author: Ryan Lortie <desrt desrt ca>
Date: Thu May 27 11:32:34 2010 -0400
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.
glib/gvariant-serialiser.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
index a94a485..be59927 100644
--- a/glib/gvariant-serialiser.c
+++ b/glib/gvariant-serialiser.c
@@ -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)
+ return;
+
g_assert_cmpint (alignment & (gsize) serialised.data, ==, 0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]