Skip to content

Commit

Permalink
Fix unsigned integers may overflow in RangeWidget
Browse files Browse the repository at this point in the history
Updated the decrement logic to prevent overflow by checking if the current value is less than the minimum plus step before performing the subtraction. This ensures safer calculations and maintains expected behavior during decrements.

Fixes #306
  • Loading branch information
forntoh committed Feb 11, 2025
1 parent 776713b commit 61c5385
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/widget/WidgetRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class WidgetRange : public BaseWidgetValue<T> {
* @return true if decremented or reset (in case of cycle)
*/
bool decrement() {
T newValue = (this->value - step < minValue) ? (cycle ? maxValue : minValue) : (this->value - step);
T newValue = (this->value < minValue + step) ? (cycle ? maxValue : minValue) : (this->value - step);
if (newValue != this->value) {
this->value = newValue;
LOG(F("WidgetRange::decrement"), this->value);
Expand Down

0 comments on commit 61c5385

Please sign in to comment.