[Spice-devel] [spice-server PATCH v1 4/12] mjpeg_encoder: fix alignment warnings (pixel_converter)

Victor Toso victortoso at redhat.com
Wed Aug 5 05:23:18 PDT 2015


As the input line could be uint8_t*, uint16_t*, uint32_t*, changing the
default from uint8_t* to void* to deal with upcasting warnings.

from clang:
mjpeg_encoder.c:260:23: error: cast from 'uint8_t *'
(aka 'unsigned char *') to 'uint16_t *' (aka 'unsigned short *')
increases required alignment from 1 to 2 [-Werror,-Wcast-align]
  uint16_t pixel = *(uint16_t *)src;
                    ^~~~~~~~~~~~~~~
---
 server/mjpeg_encoder.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/server/mjpeg_encoder.c b/server/mjpeg_encoder.c
index 9a41ef3..1d1f167 100644
--- a/server/mjpeg_encoder.c
+++ b/server/mjpeg_encoder.c
@@ -162,7 +162,7 @@ struct MJpegEncoder {
     struct jpeg_error_mgr jerr;
 
     unsigned int bytes_per_pixel; /* bytes per pixel of the input buffer */
-    void (*pixel_converter)(uint8_t *src, uint8_t *dest);
+    void (*pixel_converter)(void *src, uint8_t *dest);
 
     MJpegEncoderRateControl rate_control;
     MJpegEncoderRateControlCbs cbs;
@@ -238,15 +238,16 @@ uint8_t mjpeg_encoder_get_bytes_per_pixel(MJpegEncoder *encoder)
 
 #ifndef JCS_EXTENSIONS
 /* Pixel conversion routines */
-static void pixel_rgb24bpp_to_24(uint8_t *src, uint8_t *dest)
+static void pixel_rgb24bpp_to_24(void *src_ptr, uint8_t *dest)
 {
+    uint8_t *src = src_ptr;
     /* libjpegs stores rgb, spice/win32 stores bgr */
     *dest++ = src[2]; /* red */
     *dest++ = src[1]; /* green */
     *dest++ = src[0]; /* blue */
 }
 
-static void pixel_rgb32bpp_to_24(uint8_t *src, uint8_t *dest)
+static void pixel_rgb32bpp_to_24(void *src, uint8_t *dest)
 {
     uint32_t pixel = *(uint32_t *)src;
     *dest++ = (pixel >> 16) & 0xff;
@@ -255,7 +256,7 @@ static void pixel_rgb32bpp_to_24(uint8_t *src, uint8_t *dest)
 }
 #endif
 
-static void pixel_rgb16bpp_to_24(uint8_t *src, uint8_t *dest)
+static void pixel_rgb16bpp_to_24(void *src, uint8_t *dest)
 {
     uint16_t pixel = *(uint16_t *)src;
     *dest++ = ((pixel >> 7) & 0xf8) | ((pixel >> 12) & 0x7);
-- 
2.4.3



More information about the Spice-devel mailing list