Big endian fix: load_u24_unaligned() must be consistent with loaded_u32_to_u24()
[wimlib] / include / wimlib / unaligned.h
index 34240bd0b6e5669b9da266d7b9f9f4099a5bc2a4..3fd35a4df107e7e9140c9603e45fc6445405ebd6 100644 (file)
@@ -138,7 +138,11 @@ load_u24_unaligned(const u8 *p)
        return loaded_u32_to_u24(load_u32_unaligned(p));
 #else
 #  define LOAD_U24_REQUIRED_NBYTES 3
+#  if CPU_IS_BIG_ENDIAN
+       return ((u32)p[2] << 0) | ((u32)p[1] << 8) | ((u32)p[0] << 16);
+#  else
        return ((u32)p[0] << 0) | ((u32)p[1] << 8) | ((u32)p[2] << 16);
+#  endif
 #endif
 }