Skip to content

Commit

Permalink
Cap steps and prevent overflow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RumovZ committed Dec 10, 2021
1 parent 5fb6319 commit a224c59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions rslib/src/scheduler/states/steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ impl<'a> LearningSteps<'a> {
let next = if self.steps.len() > 1 {
self.secs_at_index(idx + 1).unwrap_or(60)
} else {
current * 2
current.saturating_mul(2)
}
.max(current);

Some((current + next) / 2)
Some(current.saturating_add(next) / 2)
} else {
None
}
Expand Down
4 changes: 3 additions & 1 deletion ts/deck-options/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ function stringToMinutes(text: string): number {
const [_, num, suffix] = match;
const unit = suffixToUnit(suffix);
const seconds = unitSeconds(unit) * parseInt(num, 10);
return seconds / 60;
// should be representable as u32 seconds on the backend
const capped_seconds = Math.min(seconds, 2 ** 32 - 1);
return capped_seconds / 60;
} else {
return 0;
}
Expand Down

0 comments on commit a224c59

Please sign in to comment.