[Spice-commits] 5 commits - common/canvas_base.c common/lz.c common/lz_decompress_tmpl.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Thu Jan 18 10:09:18 UTC 2018


 common/canvas_base.c        |   11 +++++------
 common/lz.c                 |    7 -------
 common/lz_decompress_tmpl.c |   25 +++++++++----------------
 3 files changed, 14 insertions(+), 29 deletions(-)

New commits:
commit 27e32fa8a67ae776db883a8e4353a5392bf391b8
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Dec 24 13:22:22 2017 +0000

    lz: Remove unused encode_level and only assigned io_start
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Uri Lublin <uril at redhat.com>

diff --git a/common/lz.c b/common/lz.c
index 28f450b..b7e7d48 100644
--- a/common/lz.c
+++ b/common/lz.c
@@ -90,7 +90,6 @@ typedef struct Encoder {
     // (2) a pointer to the first byte in the segment that matches the word
     HashEntry htab[HASH_SIZE];
 
-    uint8_t            *io_start;
     uint8_t            *io_now;
     uint8_t            *io_end;
     size_t io_bytes_count;
@@ -255,11 +254,6 @@ static inline void update_copy_count(Encoder *encoder, uint8_t copy_count)
     *(encoder->io_last_copy) = copy_count;
 }
 
-static inline void encode_level(Encoder *encoder, uint8_t level_code)
-{
-    *(encoder->io_start) |= level_code;
-}
-
 // decrease the io ptr by 1
 static inline void compress_output_prev(Encoder *encoder)
 {
@@ -274,7 +268,6 @@ static int encoder_reset(Encoder *encoder, uint8_t *io_ptr, uint8_t *io_ptr_end)
     spice_return_val_if_fail(io_ptr <= io_ptr_end, FALSE);
 
     encoder->io_bytes_count = io_ptr_end - io_ptr;
-    encoder->io_start = io_ptr;
     encoder->io_now = io_ptr;
     encoder->io_end = io_ptr_end;
     encoder->io_last_copy = NULL;
commit 5fda05740f6cab002172b26c1f43a4b2f6c7cae6
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Dec 21 15:56:56 2017 +0000

    lz: Simplify code
    
    Remove some conditional code always defining CAST_PLT_DISTANCE
    macro.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Uri Lublin <uril at redhat.com>

diff --git a/common/lz_decompress_tmpl.c b/common/lz_decompress_tmpl.c
index 0189f86..d445c70 100644
--- a/common/lz_decompress_tmpl.c
+++ b/common/lz_decompress_tmpl.c
@@ -153,6 +153,10 @@
 #endif // TO_RGB32
 #endif
 
+#ifndef CAST_PLT_DISTANCE
+#define CAST_PLT_DISTANCE(dist) (dist)
+#endif
+
 #ifdef LZ_A8
 #ifndef TO_RGB32
 #define OUT_PIXEL one_byte_pixel_t
@@ -261,12 +265,8 @@ static size_t FNAME(decompress)(Encoder *encoder, OUT_PIXEL *out_buf, int size)
 #endif
             ofs += 1; // offset is biased by 1       (fixing bias)
 
-#if defined(TO_RGB32)
-#if defined(PLT4_BE) || defined(PLT4_LE) || defined(PLT1_BE) || defined(PLT1_LE)
             ofs = CAST_PLT_DISTANCE(ofs);
             len = CAST_PLT_DISTANCE(len);
-#endif
-#endif
             ref -= ofs;
 
             spice_assert(op + len <= op_limit);
@@ -295,12 +295,7 @@ static size_t FNAME(decompress)(Encoder *encoder, OUT_PIXEL *out_buf, int size)
             }
         } else { // copy
             ctrl++; // copy count is biased by 1
-#if defined(TO_RGB32) && (defined(PLT4_BE) || defined(PLT4_LE) || defined(PLT1_BE) || \
-                                                                                   defined(PLT1_LE))
             spice_assert(op + CAST_PLT_DISTANCE(ctrl) <= op_limit);
-#else
-            spice_assert(op + ctrl <= op_limit);
-#endif
             COPY_COMP_PIXEL(encoder, op);
 
             spice_assert(op <= op_limit);
commit 552e842a1660bfe09c4a23763baf8f4f17d9ed5e
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Dec 21 15:55:46 2017 +0000

    lz: Avoid temporary variable
    
    Use a break to exit the loop instead of using a variable.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Uri Lublin <uril at redhat.com>

diff --git a/common/lz_decompress_tmpl.c b/common/lz_decompress_tmpl.c
index 04a5121..0189f86 100644
--- a/common/lz_decompress_tmpl.c
+++ b/common/lz_decompress_tmpl.c
@@ -222,9 +222,8 @@ static size_t FNAME(decompress)(Encoder *encoder, OUT_PIXEL *out_buf, int size)
     OUT_PIXEL    *op = out_buf;
     OUT_PIXEL    *op_limit = out_buf + size;
     uint32_t ctrl = decode(encoder);
-    int loop = TRUE;
 
-    do {
+    for (;;) {
         const OUT_PIXEL *ref = op;
         uint32_t len = ctrl >> 5;
         uint32_t ofs = (ctrl & 31) << 8; // 5 MSb of distance
@@ -312,12 +311,11 @@ static size_t FNAME(decompress)(Encoder *encoder, OUT_PIXEL *out_buf, int size)
             }
         }
 
-        if (LZ_EXPECT_CONDITIONAL(op < op_limit)) {
-            ctrl = decode(encoder);
-        } else {
-            loop = FALSE;
+        if (LZ_UNEXPECT_CONDITIONAL(op >= op_limit)) {
+            break;
         }
-    } while (LZ_EXPECT_CONDITIONAL(loop));
+        ctrl = decode(encoder);
+    }
 
     return (op - out_buf);
 }
commit 29eff61cf85573d71bec864551aa49155a209668
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Dec 22 18:42:41 2017 +0000

    canvas: Remove possible leak on LZ decompression failure
    
    longjmp can happen in different places, even after the palette
    is allocated so we need to free it if it got allocated.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Uri Lublin <uril at redhat.com>

diff --git a/common/canvas_base.c b/common/canvas_base.c
index f4f301c..b9ba37c 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -783,15 +783,17 @@ static pixman_image_t *canvas_get_lz(CanvasBase *canvas, SpiceImage *image,
     int top_down;
     int stride_encoded;
     int stride;
-    int free_palette;
+    int free_palette = FALSE;
 
     if (setjmp(lz_data->jmp_env)) {
+        if (free_palette)  {
+            free(palette);
+        }
         free(decomp_buf);
         spice_warning("%s", lz_data->message_buf);
         return NULL;
     }
 
-    free_palette = FALSE;
     if (image->descriptor.type == SPICE_IMAGE_TYPE_LZ_RGB) {
         spice_return_val_if_fail(image->u.lz_rgb.data->num_chunks == 1, NULL); /* TODO: Handle chunks */
         comp_buf = image->u.lz_rgb.data->chunk[0].data;
commit d11df6b66b64a587049f6cc82d1036571af778a7
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Dec 22 18:42:18 2017 +0000

    canvas: Simplify code using spice_memdup
    
    Instead of using spice_malloc+memcpy use spice_memdup which is
    doing the same.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Uri Lublin <uril at redhat.com>

diff --git a/common/canvas_base.c b/common/canvas_base.c
index 39439ed..f4f301c 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -737,16 +737,13 @@ static inline SpicePalette *canvas_get_localized_palette(CanvasBase *canvas, Spi
     SpicePalette *palette = canvas_get_palette(canvas, base_palette, palette_id, flags);
     SpicePalette *copy;
     uint32_t *now, *end;
-    size_t size;
 
     if (canvas->format == SPICE_SURFACE_FMT_32_xRGB ||
         canvas->format == SPICE_SURFACE_FMT_32_ARGB) {
         return palette;
     }
 
-    size = sizeof(SpicePalette) + palette->num_ents * 4;
-    copy = (SpicePalette *)spice_malloc(size);
-    memcpy(copy, palette, size);
+    copy = spice_memdup(palette, sizeof(SpicePalette) + palette->num_ents * 4);
 
     switch (canvas->format) {
     case SPICE_SURFACE_FMT_32_xRGB:


More information about the Spice-commits mailing list