* [PATCH] HID: core: don't use negative operands when shift
@ 2015-01-06 23:17 Andy Shevchenko
0 siblings, 0 replies; only message in thread
From: Andy Shevchenko @ 2015-01-06 23:17 UTC (permalink / raw)
To: Jiri Kosina, linux-input; +Cc: Andy Shevchenko
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: Andy Shevchenko <andy.shevchenko@gmail.com>
---
drivers/hid/hid-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index f2a4879..99307f0 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1027,7 +1027,7 @@ static s32 snto32(__u32 value, unsigned n)
case 16: return ((__s16)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)
--
1.8.3.101.g727a46b
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-01-06 23:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-06 23:17 [PATCH] HID: core: don't use negative operands when shift Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).