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 16-bit range check in TMenuItem::action_edit for 32-bit boards #14834

Conversation

sjasonsmith
Copy link
Contributor

@sjasonsmith sjasonsmith commented Aug 4, 2019

This was previously checking against a 32-bit range. This allowed incrementing beyond the range of encoderPosition, causing unexpected wraparound behavior.

Description

This fixes the menu item range check for 32-bit processors. The comment in this function claims to range-check for int16_t, but it actually checked the range against int. This worked for AVR, but is incorrect for 32-bit boards.

Benefits

On 32-bit boards, this prevents the value being editing from overflowing encoderPosition, before reaching the a min/max value. When editing the value, it now stops at the actual possible maximum, rather than wrapping back around to the minimum. This should make the behavior consistent with AVR boards.

The experience is still not good if the existing value falls outside the possible encoder range. In this situation the value will be coerced to the minimum value, effectively losing the user's setting. Additional code changes would be needed to prevent this, or to increase the range of the encoder.

Related Issues

This fixes the wrap-around symptom described in issue #14821.
I would not consider the issue resolved unless more work is done to allow the larger range, or at least prevent the loss of an existing value if it cannot be edited from the menu.

This was previously checking against a 32-bit range. This allowed incrementing beyond the range of encoderPosition, causing unexpected wraparound behavior.
@thinkyhead thinkyhead added PR: Bug Fix T: HAL & APIs Topic related to the HAL and internal APIs. labels Aug 6, 2019
@thinkyhead thinkyhead merged commit 534c105 into MarlinFirmware:bugfix-2.0.x Aug 6, 2019
@sjasonsmith sjasonsmith deleted the bugfix-2.0.x-menu-overflow branch August 21, 2019 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Bug Fix T: HAL & APIs Topic related to the HAL and internal APIs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants