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 overflows in WPM calculations #13128

Merged
merged 2 commits into from
Aug 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions quantum/wpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,22 @@ __attribute__((weak)) uint8_t wpm_regress_count(uint16_t keycode) {
void update_wpm(uint16_t keycode) {
if (wpm_keycode(keycode)) {
if (wpm_timer > 0) {
current_wpm += ((60000 / timer_elapsed(wpm_timer) / WPM_ESTIMATED_WORD_SIZE) - current_wpm) * wpm_smoothing;
uint16_t latest_wpm = 60000 / timer_elapsed(wpm_timer) / WPM_ESTIMATED_WORD_SIZE;
if (latest_wpm > UINT8_MAX) {
latest_wpm = UINT8_MAX;
}
current_wpm += (latest_wpm - current_wpm) * wpm_smoothing;
}
wpm_timer = timer_read();
}
#ifdef WPM_ALLOW_COUNT_REGRESSION
uint8_t regress = wpm_regress_count(keycode);
if (regress) {
current_wpm -= regress;
if (current_wpm < regress) {
current_wpm = 0;
} else {
current_wpm -= regress;
}
wpm_timer = timer_read();
}
#endif
Expand Down