commaai / panda

code powering the comma.ai panda
MIT License
1.53k stars 776 forks source link

refactor GET_BIT to be MISRA friendly #1877

Closed jyoung8607 closed 8 months ago

jyoung8607 commented 8 months ago

Refactor GET_BIT to return a bool, which makes it easier to use while maintaining MISRA compliance.

Cast directly from an int to a bool doesn't work, but old-school double-negation does the job and seems to be permitted. It did leave a single breakage in the Chrysler port. While MISRA 10.4 does make specific mention of matching essential types on both sides of a ternary op, it's not clear why it didn't think both sides were the same here. An additional cast to bool worked, so there may be a subtlety between Boolean and essentially Boolean types, or perhaps a bug in the type checker.

adeebshihadeh commented 8 months ago

Great improvement!