提交 08585e43 编写于 作者: A Andy Shevchenko 提交者: Jiri Kosina

HID: core: don't use negative operands when shift

The recent C standard in 6.5.7 paragraph 4 defines that operands for
bitwise shift operators should be non-negative, otherwise it's an
undefined behaviour.
Signed-off-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: NJiri Kosina <jkosina@suse.cz>
上级 91b9ae48
...@@ -1046,7 +1046,7 @@ static s32 snto32(__u32 value, unsigned n) ...@@ -1046,7 +1046,7 @@ static s32 snto32(__u32 value, unsigned n)
case 16: return ((__s16)value); case 16: return ((__s16)value);
case 32: return ((__s32)value); case 32: return ((__s32)value);
} }
return value & (1 << (n - 1)) ? value | (-1 << n) : value; return value & (1 << (n - 1)) ? value | (~0U << n) : value;
} }
s32 hid_snto32(__u32 value, unsigned n) s32 hid_snto32(__u32 value, unsigned n)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册