diff options
author | Ryan Lortie <desrt@desrt.ca> | 2010-05-25 11:25:34 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2010-05-25 11:26:18 -0400 |
commit | a81c2f2c7ad260bc3033648bb274a3b321df8b49 (patch) | |
tree | a16cd919d0db8892d3e71c6406db7eb74acca7d2 /glib/gvariant-serialiser.c | |
parent | 9e25ec592ba32797230650b2236935deb2022960 (diff) | |
download | glib-a81c2f2c7ad260bc3033648bb274a3b321df8b49.tar.gz |
GVariant: deal with non-8-aligned malloc()
Closes bug #619585.
Diffstat (limited to 'glib/gvariant-serialiser.c')
-rw-r--r-- | glib/gvariant-serialiser.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c index cf23812c9..a94a485e5 100644 --- a/glib/gvariant-serialiser.c +++ b/glib/gvariant-serialiser.c @@ -139,6 +139,24 @@ g_variant_serialised_check (GVariantSerialised serialised) else g_assert (serialised.size == 0 || serialised.data != NULL); + /* Depending on the native alignment requirements of the machine, the + * compiler will insert either 3 or 7 padding bytes after the char. + * This will result in the sizeof() the struct being 12 or 16. + * Subtract 9 to get 3 or 7 which is a nice bitmask to apply to get + * the alignment bits that we "care about" being zero: in the + * 4-aligned case, we care about 2 bits, and in the 8-aligned case, we + * care about 3 bits. + */ + alignment &= sizeof (struct { + char a; + union { + guint64 x; + void *y; + gdouble z; + } b; + } + ) - 9; + g_assert_cmpint (alignment & (gsize) serialised.data, ==, 0); } |