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

Fix KeyAddrEventQueue::shouldAbort() (qukeys getting stuck) #1321

Merged
merged 2 commits into from Dec 24, 2022

Conversation

gedankenexperimenter
Copy link
Collaborator

This fixes a problem that was causing key events to get dropped in some cases when the event id rolled over from positive to negative values while a plugin had events queued spanning both sides of the overflow. This would generally result in event 127 getting dropped. If the dropped event was a keyswitch toggling on, the key would be unresponsive. If it was a key release, the key would get "stuck on".

The problem was that the 8-bit integer KeyEventId values were getting promoted to 16-bit integers when computing the difference between the event being flushed from the queue and the event at the head of the queue. The resulting 16-bit value (-128 - 127) would be negative, whereas its 8-bit counterpart would be positive, resulting in a false positive return value from shouldAbort(). The fix is to convert the difference back to an 8-bit integer before doing the comparison with zero.

I've included a testcase that fails without the fix.

This test reproduces a bug where key events can get dropped by plugins that use
KeyAddrEventQueue, causing keys to be non-responsive or getting stuck on.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
The compiler promotes our signed 8-bit integer to a 16-bit integer, at least on
some processors.  This causes the wrong result for `shouldAbort()` when the new
event's id is -128, and the one at the head of the queue is 127.

Fixes keyboardio#1320

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
@gedankenexperimenter gedankenexperimenter added bug Something isn't working plugin:qukeys Issues related to Qukeys labels Dec 24, 2022
@gedankenexperimenter gedankenexperimenter self-assigned this Dec 24, 2022
@obra
Copy link
Member

obra commented Dec 24, 2022

Thank you!

@obra obra merged commit 904722f into keyboardio:master Dec 24, 2022
@gedankenexperimenter gedankenexperimenter deleted the fix-should-abort branch December 24, 2022 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin:qukeys Issues related to Qukeys
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants