[Spice-devel] Alignment of data within spice packets
Victor Toso
lists at victortoso.com
Wed Mar 8 21:16:36 UTC 2017
Hi,
On Wed, Mar 08, 2017 at 07:21:15PM +0100, Christophe de Dinechin wrote:
> I have several errors like this:
>
> spice-channel.c:1923:12: error: cast from 'uint8_t *' (aka 'unsigned char *') to
> 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to
> 4 [-Werror,-Wcast-align]
> ...(uint32_t *)((uint8_t *)c->peer_msg + GUINT32_FROM_LE(c->peer_msg->caps_offset));
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Is there any guarantee that the result pointer will be 32-bit aligned?
> In other words, is it guaranteed that the c->peer_msg->caps_offset
> will be a multiple of 4? I don’t see this written in the spec.
>
> Based on the answer, the correct fix is:
>
> - If aligned, to cast to a uint32_t * in a way that disables the warning
>
> - If misaligned, to replaced *p with a read operation that is safe when mis-aligned (OS dependent I guess)
Yes, we should check case-by-case. I started doing some work around this
(nearly one and half year ago already!) but I got stuck on explaining
the rationale for each cast which would avoid the warnings.
You can see the comments and suggestions at the time are in the
following thread:
https://lists.freedesktop.org/archives/spice-devel/2015-August/021535.html
Cheers,
toso
>
>
> Thanks
> Christophe
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170308/0c4eb238/attachment-0001.sig>
More information about the Spice-devel
mailing list