From baf9a20c08738d3a207a3a9277ea7fe08fb16cdf Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 23 Dec 2019 22:51:40 +0300 Subject: [PATCH] Fix UB in to_u8 Possible signed shift overflow. --- Utilities/types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utilities/types.h b/Utilities/types.h index fb2a1e0c09..1439b00fb4 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -529,7 +529,7 @@ struct offset32_detail }; // Helper function, used by ""_u16, ""_u32, ""_u64 -constexpr u8 to_u8(char c) +constexpr u32 to_u8(char c) { return static_cast(c); } @@ -539,7 +539,7 @@ constexpr u16 operator""_u16(const char* s, std::size_t length) { return #if IS_LE_MACHINE == 1 - to_u8(s[1]) << 8 | to_u8(s[0]); + static_cast(to_u8(s[1]) << 8 | to_u8(s[0])); #endif }