[Spice-devel] Alignment of data within spice packets

Victor Toso victortoso at redhat.com
Thu Mar 9 13:12:24 UTC 2017


Hi,

On Thu, Mar 09, 2017 at 12:46:09PM +0100, Christophe de Dinechin wrote:
> 
> > On 8 Mar 2017, at 22:16, Victor Toso <lists at victortoso.com> wrote:
> > 
> > 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 <https://lists.freedesktop.org/archives/spice-devel/2015-August/021535.html>
> 
> Ach, I see you used SPICE_ALIGNED_CAST and SPICE_UNALIGNED_CAST. I
> used SPICE_REALIGN_CAST :-(
>
> Will try to integrate your patches, thanks.

Feel free to take the solution that works best for you based on the
comments from Frediano/Christophe there. The hard part is not casting
around but properly explaining :-)

I'd be super happy if we can build with clang without warnings
(excluding vala) :)

>
> > 
> > Cheers,
> >        toso
> >> 
> >> 
> >> Thanks
> >> Christophe
> >> 
> >> _______________________________________________
> >> Spice-devel mailing list
> >> Spice-devel at lists.freedesktop.org <mailto:Spice-devel at lists.freedesktop.org>
> >> https://lists.freedesktop.org/mailman/listinfo/spice-devel <https://lists.freedesktop.org/mailman/listinfo/spice-devel>

> _______________________________________________
> 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/20170309/253789a9/attachment.sig>


More information about the Spice-devel mailing list