From dfab15ed781fd780146d7592d4e0a86d6c31b4cc Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Mon, 18 Nov 2019 16:36:17 +0100 Subject: [PATCH 1/2] Fixed internal overflow on subtraiton in elapsed and duration --- CHANGELOG.md | 5 +++++ src/cyccnt.rs | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c96df3c5a2..5a5cdec063 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/src/cyccnt.rs b/src/cyccnt.rs index 86969cb1a3..338bbbeaea 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 } } From ebd62215ff05bd0a43a17539e39b92fac8d024cb Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Mon, 18 Nov 2019 16:38:52 +0100 Subject: [PATCH 2/2] Bumped version to 0.5.1, cyccntr bugfix --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 56ef2aca43..ce371f931c 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"