[Spice-devel] [PATCH spice-gtk v6 4/4] Address alignment warnings detected by clang

Christophe de Dinechin christophe at dinechin.org
Wed May 31 12:46:54 UTC 2017


From: Christophe de Dinechin <dinechin at redhat.com>

Signed-off-by: Christophe de Dinechin <dinechin at redhat.com>
---
 src/channel-cursor.c |  8 +++++---
 src/spice-channel.c  | 17 ++++++++++-------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/channel-cursor.c b/src/channel-cursor.c
index 85160eb..b9309d8 100644
--- a/src/channel-cursor.c
+++ b/src/channel-cursor.c
@@ -385,6 +385,7 @@ static display_cursor *set_cursor(SpiceChannel *channel, SpiceCursor *scursor)
     const guint8* data;
     guint8 *rgba;
     guint8 val;
+    gint palette[16];
 
     CHANNEL_DEBUG(channel, "%s: flags %x, size %u", __FUNCTION__,
                   scursor->flags, scursor->data_size);
@@ -422,7 +423,7 @@ static display_cursor *set_cursor(SpiceChannel *channel, SpiceCursor *scursor)
         memcpy(cursor->data, data, size);
         for (i = 0; i < hdr->width * hdr->height; i++) {
             pix_mask = get_pix_mask(data, size, i);
-            if (pix_mask && *(SPICE_ALIGNED_CAST(guint32 *, data) + i) == 0xffffff) {
+            if (pix_mask && cursor->data[i] == 0xffffff) {
                 cursor->data[i] = get_pix_hack(i, hdr->width);
             } else {
                 cursor->data[i] |= (pix_mask ? 0 : 0xff000000);
@@ -432,7 +433,7 @@ static display_cursor *set_cursor(SpiceChannel *channel, SpiceCursor *scursor)
     case SPICE_CURSOR_TYPE_COLOR16:
         for (i = 0; i < hdr->width * hdr->height; i++) {
             pix_mask = get_pix_mask(data, size, i);
-            pix = *(SPICE_ALIGNED_CAST(guint16 *, data) + i);
+            pix = *(SPICE_UNALIGNED_CAST(guint16 *, data) + i);
             if (pix_mask && pix == 0x7fff) {
                 cursor->data[i] = get_pix_hack(i, hdr->width);
             } else {
@@ -443,10 +444,11 @@ static display_cursor *set_cursor(SpiceChannel *channel, SpiceCursor *scursor)
         break;
     case SPICE_CURSOR_TYPE_COLOR4:
         size = ((unsigned int)(SPICE_ALIGN(hdr->width, 2) / 2)) * hdr->height;
+        memcpy(palette, data + size, sizeof(palette));
         for (i = 0; i < hdr->width * hdr->height; i++) {
             pix_mask = get_pix_mask(data, size + (sizeof(uint32_t) << 4), i);
             int idx = (i & 1) ? (data[i >> 1] & 0x0f) : ((data[i >> 1] & 0xf0) >> 4);
-            pix = *(SPICE_UNALIGNED_CAST(uint32_t *, (data + size)) + idx);
+            pix = palette[idx];
             if (pix_mask && pix == 0xffffff) {
                 cursor->data[i] = get_pix_hack(i, hdr->width);
             } else {
diff --git a/src/spice-channel.c b/src/spice-channel.c
index 6c52547..18b6a7c 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1930,18 +1930,21 @@ static gboolean spice_channel_recv_link_msg(SpiceChannel *channel)
     /* g_return_if_fail(c->peer_msg + c->peer_msg->caps_offset * sizeof(uint32_t) > c->peer_msg + c->peer_hdr.size); */
 
     caps_src = (uint8_t *)c->peer_msg + GUINT32_FROM_LE(c->peer_msg->caps_offset);
-    caps = SPICE_UNALIGNED_CAST(uint32_t *, caps_src);
 
-    g_array_set_size(c->remote_common_caps, num_common_caps);
+    g_array_set_size(c->remote_common_caps, num_common_caps * sizeof(uint32_t));
+    caps = &g_array_index(c->remote_common_caps, uint32_t, 0);
+    memcpy(caps, caps_src, num_common_caps * sizeof(uint32_t));
     for (i = 0; i < num_common_caps; i++, caps++) {
-        g_array_index(c->remote_common_caps, uint32_t, i) = GUINT32_FROM_LE(*caps);
-        CHANNEL_DEBUG(channel, "got common caps %d:0x%X", i, GUINT32_FROM_LE(*caps));
+        *caps = GUINT32_FROM_LE(*caps);
+        CHANNEL_DEBUG(channel, "got common caps %d:0x%X", i, *caps);
     }
 
-    g_array_set_size(c->remote_caps, num_channel_caps);
+    g_array_set_size(c->remote_caps, num_channel_caps * sizeof(uint32_t));
+    caps_src += num_common_caps * sizeof(uint32_t);
+    memcpy(caps, caps_src, num_channel_caps * sizeof(uint32_t));
     for (i = 0; i < num_channel_caps; i++, caps++) {
-        g_array_index(c->remote_caps, uint32_t, i) = GUINT32_FROM_LE(*caps);
-        CHANNEL_DEBUG(channel, "got channel caps %d:0x%X", i, GUINT32_FROM_LE(*caps));
+        *caps = GUINT32_FROM_LE(*caps);
+        CHANNEL_DEBUG(channel, "got channel caps %d:0x%X", i, *caps);
     }
 
     if (!spice_channel_test_common_capability(channel,
-- 
2.11.0 (Apple Git-81)



More information about the Spice-devel mailing list