Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code logic flaw in `app/driver/rotary,c #2823

Closed
TerryE opened this issue Jul 7, 2019 · 3 comments
Closed

Code logic flaw in `app/driver/rotary,c #2823

TerryE opened this issue Jul 7, 2019 · 3 comments
Assignees
Labels

Comments

@TerryE
Copy link
Collaborator

TerryE commented Jul 7, 2019

As part of my pre lua53 cleanup , I am adding -Wall to the lua and drivers directories. In the case of the latter this has thrown up a bug in rotary.c. The macro at L40

#define STATUS_IS_PRESSED(x) ((x & 0x80000000) != 0)

has the parentheses around x in the expansion missing which means that the use in L175 generates

|| (last_status ^ new_status & 0x80000000) != 0)

which is not the same as the intended

|| ((last_status ^ new_status) & 0x80000000) != 0)

because the & operator has a higher precedence than ^. Ditto L176.

I've added the extra guard parenthesis for my cleanup so my next PR will fix this, but perhaps @pjsg could confirm that this is correct.

@TerryE TerryE added the bug label Jul 7, 2019
@TerryE TerryE assigned TerryE and pjsg Jul 7, 2019
@pjsg
Copy link
Member

pjsg commented Jul 8, 2019

You are entirely correct -- there should be parens around the x. However, it doesn't actually make much difference. In the driver, this is used to determine whether it is worth waking up the task to handle a message. The module layer gets it correct (I think). Thus there is no functional impact, but there is a performance impact.

Thanks for fixing.

@TerryE
Copy link
Collaborator Author

TerryE commented Jul 8, 2019

I picked up a couple of these in my own code when I turned on -Wall 😝

@TerryE
Copy link
Collaborator Author

TerryE commented Sep 12, 2019

fixed in #2836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants