From 6ac6255afabd5ce3a469a1247e239398df320d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Tue, 15 Sep 2020 01:03:03 -0700 Subject: [PATCH] include: avoid UB with signed overflow/shift (#1675) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if integer is 32-bit, and numeric literals default to int type, the following applies (from The C Standard, 6.5.7, paragraph 4 [ISO/IEC 9899:2011]): If E1 has a signed type and nonnegative value, and E1 × 2^E2 is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined. which means that the only way to safely shift is unsigned, so use 1U to indicate the shifted bit is unsigned. --- include/capstone/capstone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/capstone/capstone.h b/include/capstone/capstone.h index 30dc5742..204a092b 100644 --- a/include/capstone/capstone.h +++ b/include/capstone/capstone.h @@ -121,7 +121,7 @@ typedef enum cs_mode { CS_MODE_M68K_030 = 1 << 4, ///< M68K 68030 mode CS_MODE_M68K_040 = 1 << 5, ///< M68K 68040 mode CS_MODE_M68K_060 = 1 << 6, ///< M68K 68060 mode - CS_MODE_BIG_ENDIAN = 1 << 31, ///< big-endian mode + CS_MODE_BIG_ENDIAN = 1U << 31, ///< big-endian mode CS_MODE_MIPS32 = CS_MODE_32, ///< Mips32 ISA (Mips) CS_MODE_MIPS64 = CS_MODE_64, ///< Mips64 ISA (Mips) CS_MODE_M680X_6301 = 1 << 1, ///< M680X Hitachi 6301,6303 mode