aboutsummaryrefslogtreecommitdiff
path: root/src/cyccnt.rs
diff options
context:
space:
mode:
authorGravatar Per Lindgren <per.lindgren@ltu.se> 2019-11-18 16:36:17 +0100
committerGravatar Per Lindgren <per.lindgren@ltu.se> 2019-11-18 16:36:17 +0100
commitdfab15ed781fd780146d7592d4e0a86d6c31b4cc (patch)
tree9d274803cce759e162cef9fc84d7267f12c93aff /src/cyccnt.rs
parent725d5e1aa9d0276783765dcabe5430f03ea13dd5 (diff)
downloadrtic-dfab15ed781fd780146d7592d4e0a86d6c31b4cc.tar.gz
rtic-dfab15ed781fd780146d7592d4e0a86d6c31b4cc.tar.zst
rtic-dfab15ed781fd780146d7592d4e0a86d6c31b4cc.zip
Fixed internal overflow on subtraiton in elapsed and duration
Diffstat (limited to '')
-rw-r--r--src/cyccnt.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/cyccnt.rs b/src/cyccnt.rs
index 86969cb1..338bbbea 100644
--- a/src/cyccnt.rs
+++ b/src/cyccnt.rs
@@ -38,12 +38,14 @@ impl Instant {
/// Returns the amount of time elapsed since this instant was created.
pub fn elapsed(&self) -> Duration {
- Instant::now() - *self
+ let diff = Instant::now().inner.wrapping_sub(self.inner);
+ assert!(diff >= 0, "instant now is earlier than self");
+ Duration { inner: diff as u32 }
}
/// Returns the amount of time elapsed from another instant to this one.
pub fn duration_since(&self, earlier: Instant) -> Duration {
- let diff = self.inner - earlier.inner;
+ let diff = self.inner.wrapping_sub(earlier.inner);
assert!(diff >= 0, "second instant is later than self");
Duration { inner: diff as u32 }
}