Re: Dict parsing question

Lawrence D'Oliveiro <ldo-kC51rjc0cqs1dNLGKZg6taU/[email protected]> Wed, 3 Jan 2024 10:28:03 +1300
Newsgroups gmane.comp.freedesktop.dbus
Organization Geek Central
Message-ID <[email protected]>
On Tue, 2 Jan 2024 11:47:30 +0000, Simon McVittie wrote:

> This is not just dicts: the elements of an array of (u)int64 or double
> have the same property that the 8-byte alignment of each element is
> greater than the 4-byte alignment of the first byte of the array
> length. This just means that you might need padding between the
> array length and the actual content (the first element).

But you don’t know on what boundary the array length is positioned: if
it’s already at an address that is a multiple of 8 bytes (which could
happen, say, 50% of the time), then the addition of 4 bytes of padding
means the element field is no longer 8-byte-aligned.

This is why, in order to have 8-byte alignment for the elements of a
structure, you have to guarantee at least 8-byte alignment for the
structure itself.