[Spice-commits] 3 commits - server/dcc-send.c server/lz4-encoder.c server/utils.c server/utils.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Mon Jan 29 21:14:10 UTC 2018


 server/dcc-send.c    |   10 ++++++----
 server/lz4-encoder.c |    2 +-
 server/utils.c       |    7 ++++---
 server/utils.h       |    2 +-
 4 files changed, 12 insertions(+), 9 deletions(-)

New commits:
commit 1a7c715b1022c973176c24b5b9eb181011487e36
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Jan 22 16:07:17 2018 +0000

    dcc-send: Avoid to use unaligned memory
    
    This causes some warnings with clang:
    
    dcc-send.c:1799:28: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
        num_surfaces_created = (uint32_t *)spice_marshaller_reserve_space(m2, sizeof(uint32_t));
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This also fixes some endianness issue (on big endian machine integers
    were not properly encoded).
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Victor Toso <victortoso at redhat.com>

diff --git a/server/dcc-send.c b/server/dcc-send.c
index 364f3405..211c69d7 100644
--- a/server/dcc-send.c
+++ b/server/dcc-send.c
@@ -1793,11 +1793,12 @@ static void display_channel_marshall_migrate_data_surfaces(DisplayChannelClient
                                                            int lossy)
 {
     SpiceMarshaller *m2 = spice_marshaller_get_ptr_submarshaller(m, 0);
-    uint32_t *num_surfaces_created;
+    uint32_t num_surfaces_created;
+    uint8_t *num_surfaces_created_ptr;
     uint32_t i;
 
-    num_surfaces_created = (uint32_t *)spice_marshaller_reserve_space(m2, sizeof(uint32_t));
-    *num_surfaces_created = 0;
+    num_surfaces_created_ptr = spice_marshaller_reserve_space(m2, sizeof(uint32_t));
+    num_surfaces_created = 0;
     for (i = 0; i < NUM_SURFACES; i++) {
         SpiceRect lossy_rect;
 
@@ -1805,7 +1806,7 @@ static void display_channel_marshall_migrate_data_surfaces(DisplayChannelClient
             continue;
         }
         spice_marshaller_add_uint32(m2, i);
-        (*num_surfaces_created)++;
+        num_surfaces_created++;
 
         if (!lossy) {
             continue;
@@ -1816,6 +1817,7 @@ static void display_channel_marshall_migrate_data_surfaces(DisplayChannelClient
         spice_marshaller_add_int32(m2, lossy_rect.right);
         spice_marshaller_add_int32(m2, lossy_rect.bottom);
     }
+    spice_marshaller_set_uint32(m2, num_surfaces_created_ptr, num_surfaces_created);
 }
 
 static void display_channel_marshall_migrate_data(RedChannelClient *rcc,
commit 497b8042dcc135f4c5f6b77a971cc6aaa661c094
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Jan 22 17:38:23 2018 +0000

    lz4-encoder: Use GUINT32_TO_BE instead of htonl
    
    Just a style change, almost of the code use similar macros for such
    tasks.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Victor Toso <victortoso at redhat.com>

diff --git a/server/lz4-encoder.c b/server/lz4-encoder.c
index 39aac012..a8f0d17c 100644
--- a/server/lz4-encoder.c
+++ b/server/lz4-encoder.c
@@ -89,7 +89,7 @@ int lz4_encode(Lz4EncoderContext *lz4, int height, int stride, uint8_t *io_ptr,
             LZ4_freeStream(stream);
             return 0;
         }
-        *((uint32_t *)compressed_lines) = htonl(enc_size);
+        *((uint32_t *)compressed_lines) = GUINT32_TO_BE(enc_size);
 
         out_size += enc_size += 4;
         already_copied = 0;
commit 03125ef9509c0fe6e6664cccf12e499203516066
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Jan 22 17:36:35 2018 +0000

    utils: Use const for rgb32_data_has_alpha data argument
    
    There's no reason to change data passed, the function just check
    the alpha channel of the image.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Victor Toso <victortoso at redhat.com>

diff --git a/server/utils.c b/server/utils.c
index 746132e5..1856db61 100644
--- a/server/utils.c
+++ b/server/utils.c
@@ -25,14 +25,15 @@
 #include "utils.h"
 
 int rgb32_data_has_alpha(int width, int height, size_t stride,
-                         uint8_t *data, int *all_set_out)
+                         const uint8_t *data, int *all_set_out)
 {
-    uint32_t *line, *end, alpha;
+    const uint32_t *line, *end;
+    uint32_t alpha;
     int has_alpha;
 
     has_alpha = FALSE;
     while (height-- > 0) {
-        line = (uint32_t *)data;
+        line = (const uint32_t *)data;
         end = line + width;
         data += stride;
         while (line != end) {
diff --git a/server/utils.h b/server/utils.h
index 3f735754..58d43caf 100644
--- a/server/utils.h
+++ b/server/utils.h
@@ -72,7 +72,7 @@ static inline red_time_t spice_get_monotonic_time_ms(void)
 }
 
 int rgb32_data_has_alpha(int width, int height, size_t stride,
-                         uint8_t *data, int *all_set_out);
+                         const uint8_t *data, int *all_set_out);
 
 const char *red_channel_type_to_str(int type);
 int red_channel_name_to_type(const char *name);


More information about the Spice-commits mailing list