]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
types: Add missing casts in compile-time byteswaps
authorVladimir Serbinenko <phcoder@gmail.com>
Thu, 16 May 2024 19:22:58 +0000 (22:22 +0300)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 6 Jun 2024 14:55:16 +0000 (16:55 +0200)
Without them, e.g., 0x80LL on 64-bit target is 32-bit byte-swapped to
0xffffffff80000000 instead of correct 0x80000000.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
include/grub/types.h

index 064066e2e18449ef90216aff43591dd63286e387..45079bf65403fb02db2e2bc7bb759b6ad2c22222 100644 (file)
@@ -196,8 +196,8 @@ static inline grub_uint16_t grub_swap_bytes16(grub_uint16_t _x)
    return (grub_uint16_t) ((_x << 8) | (_x >> 8));
 }
 
-#define grub_swap_bytes16_compile_time(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
-#define grub_swap_bytes32_compile_time(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000UL) >> 24))
+#define grub_swap_bytes16_compile_time(x) ((grub_uint16_t)((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8)))
+#define grub_swap_bytes32_compile_time(x) ((grub_uint32_t)((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000UL) >> 24)))
 #define grub_swap_bytes64_compile_time(x)      \
 ({ \
    grub_uint64_t _x = (x); \