On Thu, Aug 22, 2019 at 04:39:33PM -0300, Mauro Carvalho Chehab wrote:
> Doing something like:
> 
>       i32 foo = 1, bar;
> 
>       bar = foo << 31;
> 
> has an undefined behavior in C, as warned by cppcheck, as we're
> shifting a signed integer.
> 
> Instead, force the numbers to be unsigned, in order to solve this
> issue.

I also recommend using the BIT() macro, which does the ULing correctly,
etc.

i.e. instead of:

-       keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
+       keyup = (gpio & ir->mask_keyup) ? 1UL << 31 : 0;

use:

-       keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
+       keyup = (gpio & ir->mask_keyup) ? BIT(31) : 0;

-- 
Kees Cook

Reply via email to