[Spice-devel] [PATCH spice-common 1/5] canvas: Simplify code using spice_memdup

Frediano Ziglio fziglio at redhat.com
Wed Jan 17 15:55:16 UTC 2018


Instead of using spice_malloc+memcpy use spice_memdup which is
doing the same.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 common/canvas_base.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

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:
-- 
2.14.3



More information about the Spice-devel mailing list