Skip to content

Commit

Permalink
Catch Range::random() divide-by-zero condition, fix off-by-1 error (#…
Browse files Browse the repository at this point in the history
…2559)

e.g. min=0, max=10 then range=11 not 10
  • Loading branch information
mikee47 authored Sep 28, 2022
1 parent 34a796f commit 16b33c6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sming/Core/Data/Range.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ template <typename T> struct TRange {
*/
T random() const
{
auto n = 1 + max - min;
if(n == 0) {
return 0;
}
auto value = os_random();
return min + value % (max - min);
return min + value % n;
}

Iterator begin() const
Expand Down

0 comments on commit 16b33c6

Please sign in to comment.