image-loader: Fix undefined left shift in premultiply_data
authorAdam Jackson <ajax@redhat.com>
Wed, 16 Oct 2019 20:06:06 +0000 (16:06 -0400)
committerAdam Jackson <ajax@redhat.com>
Wed, 16 Oct 2019 20:06:06 +0000 (16:06 -0400)
../shared/image-loader.c:184:14: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'

Store each channel in a uint32_t instead of a byte so we compute the shift over
an unsigned type.

shared/image-loader.c

index 8686e02a3fbc5eff30dac0220718bea25ad72eb1..2385c7a0e6cfa8f482e062dc2fe0ac8e2a44d8be 100644 (file)
@@ -166,15 +166,15 @@ premultiply_data(png_structp   png,
     png_bytep p;
 
     for (i = 0, p = data; i < row_info->rowbytes; i += 4, p += 4) {
-       png_byte  alpha = p[3];
+       uint32_t alpha = p[3];
        uint32_t w;
 
        if (alpha == 0) {
                w = 0;
        } else {
-               png_byte red   = p[0];
-               png_byte green = p[1];
-               png_byte blue  = p[2];
+               uint32_t red   = p[0];
+               uint32_t green = p[1];
+               uint32_t blue  = p[2];
 
                if (alpha != 0xff) {
                        red   = multiply_alpha(alpha, red);