[Spice-devel] [PATCH spice-server 10/10] utils: Avoid possible unaligned access

Victor Toso victortoso at redhat.com
Wed Jan 31 14:01:48 UTC 2018


Hi,

On Mon, Jan 22, 2018 at 05:55:02PM +0000, Frediano Ziglio wrote:
> Code in rgb32_data_has_alpha possibly generate this warning using
> clang:
> 
> utils.c:35:16: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
>         line = (uint32_t *)data;
>                ^~~~~~~~~~~~~~~~
> 
> Although the images are expected to be all aligned in this respect
> use byte access on the data instead. This, beside fixing the alignment
> issue also avoid problem with big endian machines (images in SPICE are
> expected to have the alpha channel as the forth byte).
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>

Looks good,
Acked-by: Victor Toso <victortoso at redhat.com>

> ---
>  server/utils.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/server/utils.c b/server/utils.c
> index 1856db61..b8a40b1d 100644
> --- a/server/utils.c
> +++ b/server/utils.c
> @@ -27,25 +27,25 @@
>  int rgb32_data_has_alpha(int width, int height, size_t stride,
>                           const uint8_t *data, int *all_set_out)
>  {
> -    const uint32_t *line, *end;
> -    uint32_t alpha;
> +    const uint8_t *line, *end;
> +    uint8_t alpha;
>      int has_alpha;
>  
>      has_alpha = FALSE;
>      while (height-- > 0) {
> -        line = (const uint32_t *)data;
> -        end = line + width;
> +        line = data;
> +        end = line + sizeof(uint32_t) * width;
>          data += stride;
>          while (line != end) {
> -            alpha = *line & 0xff000000U;
> +            alpha = line[3];
>              if (alpha != 0) {
>                  has_alpha = TRUE;
> -                if (alpha != 0xff000000U) {
> +                if (alpha != 0xffU) {
>                      *all_set_out = FALSE;
>                      return TRUE;
>                  }
>              }
> -            line++;
> +            line += sizeof(uint32_t);
>          }
>      }
>  
> -- 
> 2.14.3
> 
> _______________________________________________
> 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: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180131/3e3dc6b2/attachment-0001.sig>


More information about the Spice-devel mailing list