cast to unsigned int before shifting left
authorMarcus Meissner <marcus@jet.franken.de>
Sat, 18 Jan 2020 18:50:38 +0000 (19:50 +0100)
committerMarcus Meissner <marcus@jet.franken.de>
Sat, 18 Jan 2020 18:50:38 +0000 (19:50 +0100)
(weird integer promotion, a unsigned char will be first tried to be promoted to "int" apparently,
so we need to cast it to avoid implicit behaviour)

fixes https://github.com/libexif/libexif/issues/20

libexif/exif-utils.c

index 9083ddc..8a92907 100644 (file)
@@ -132,9 +132,9 @@ exif_get_slong (const unsigned char *b, ExifByteOrder order)
        if (!b) return 0;
         switch (order) {
         case EXIF_BYTE_ORDER_MOTOROLA:
-                return ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
+                return (((uint32_t)b[0] << 24) | ((uint32_t)b[1] << 16) | ((uint32_t)b[2] << 8) | (uint32_t)b[3]);
         case EXIF_BYTE_ORDER_INTEL:
-                return ((b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0]);
+                return (((uint32_t)b[3] << 24) | ((uint32_t)b[2] << 16) | ((uint32_t)b[1] << 8) | (uint32_t)b[0]);
         }
 
        /* Won't be reached */