handle negative timer delta (#2110)

This commit is contained in:
Matthew Kennedy 2020-12-21 03:16:58 -08:00 committed by GitHub
parent ce802ae43e
commit 67d0d7b330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -37,6 +37,13 @@ float Timer::getElapsedSeconds() const {
float Timer::getElapsedSeconds(efitick_t nowNt) const {
auto delta = nowNt - m_lastReset;
// Yes, things can happen slightly in the future if we get a lucky interrupt between
// the timestamp and this subtraction, that updates m_lastReset to what's now "the future",
// resulting in a negative delta.
if (delta < 0) {
return 0;
}
if (delta > UINT32_MAX - 1) {
delta = UINT32_MAX - 1;
}