aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2019-11-18 20:07:06 +0000
committerGravatar GitHub <noreply@github.com> 2019-11-18 20:07:06 +0000
commit8374fce0dfbc945f878b9c0f5525ce8d48aaa428 (patch)
tree3638bffb95fd61b32e2281e3336152f71eb7642f
parent725d5e1aa9d0276783765dcabe5430f03ea13dd5 (diff)
parentebd62215ff05bd0a43a17539e39b92fac8d024cb (diff)
downloadrtic-8374fce0dfbc945f878b9c0f5525ce8d48aaa428.tar.gz
rtic-8374fce0dfbc945f878b9c0f5525ce8d48aaa428.tar.zst
rtic-8374fce0dfbc945f878b9c0f5525ce8d48aaa428.zip
Merge #278
278: Cyccnt r=texitoi a=perlindgren The subtractions in `elapsed` and `duration` may cause an overflow panic in debug mode. This is solved by using wrapping arithmetics. Co-authored-by: Per Lindgren <per.lindgren@ltu.se>
-rw-r--r--CHANGELOG.md5
-rw-r--r--Cargo.toml2
-rw-r--r--src/cyccnt.rs6
3 files changed, 10 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c96df3c5..5a5cdec0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+## v0.5.1 - 2019-11-18
+- Fixed arithmetic wrapping bug in src/cyccntr.rs
+ elapsed and duration could cause an internal overflow trap
+ on subtraction in debug mode.
+
## v0.5.0 - 2019-11-14
### Added
diff --git a/Cargo.toml b/Cargo.toml
index 56ef2aca..ce371f93 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
name = "cortex-m-rtfm"
readme = "README.md"
repository = "https://github.com/rtfm-rs/cortex-m-rtfm"
-version = "0.5.0"
+version = "0.5.1"
[lib]
name = "rtfm"
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 }
}