-
Notifications
You must be signed in to change notification settings - Fork 128
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
keymap: fix modular arithmetic #671
Conversation
5b54b39
to
37b415d
Compare
37b415d
to
29d22b3
Compare
Good catch! I fixed the compilation error, added a test and further comments. |
Note that this is unlikely to trigger:
So this explains it was undetected for so long. |
This causes a segfault in SDL because it initializes its group to -1 and then calls |
What is SDL? Do you have a link to the corresponding bug report? |
https://github.com/libsdl-org/SDL There is no bug report. I encountered this when running https://gitlab.com/amini-allight/radv-bug-demo/. It only triggers if the first group does not have a name, i.e., |
While we will try to release soon with the fix, it seems still quite unlikely to trigger the bug in usual situations, e.g. when taking the state from the compositor (in the context of my previous comment). |
29d22b3
to
5d88c43
Compare
Added changelog entry and more tests, especially every function in the API taking a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The modular arithmetic is incorrect for negative values, e.g. for num_groups = 1. It triggers a segfault for the following settings: - layouts count (per key or total) N: `N > 0`, and - layout index n: `n = - k * N` (`k > 0`) % returns the *remainder* of the division, not the modulus (see C11 standard 6.5.5 “Multiplicative operators”: a % b = a - (a/b)*b. While both operators return the same result for positive operands, they do not for e.g. a negative dividend: remainder may be negative (in the open interval ]-num_groups, num_groups[) while the modulus is always positive. So if the remainder is negative, we must add `num_groups` to get the modulus. Fixes: 67b03ce ("state: correctly wrap state->locked_group and ->group") Signed-off-by: Julian Orth <[email protected]> Co-authored-by: Julian Orth <[email protected]> Co-authored-by: Pierre Le Marre <[email protected]>
5d88c43
to
d397668
Compare
Consider num_groups = 1.
Fixes: 67b03ce ("state: correctly wrap state->locked_group and ->group")
This should be backported.