From 5307407e7b0715edd0bf2f65aad635b37590c8a7 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Fri, 10 Nov 2023 15:34:39 +0300 Subject: [PATCH 1/2] fix indexes_as_range --- svd-rs/CHANGELOG.md | 2 ++ svd-rs/src/dimelement.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/svd-rs/CHANGELOG.md b/svd-rs/CHANGELOG.md index 00711468..1b239f2f 100644 --- a/svd-rs/CHANGELOG.md +++ b/svd-rs/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +- Fix `indexes_as_range` + ## [v0.14.3] - 2023-04-04 - Bump MSRV to 1.58.0 diff --git a/svd-rs/src/dimelement.rs b/svd-rs/src/dimelement.rs index 7910a4ff..67522f41 100644 --- a/svd-rs/src/dimelement.rs +++ b/svd-rs/src/dimelement.rs @@ -170,7 +170,11 @@ impl DimElement { pub fn indexes_as_range(&self) -> Option> { let mut integers = Vec::with_capacity(self.dim as usize); for idx in self.indexes() { - integers.push(idx.parse::().ok()?); + let val = idx.parse::().ok()?; + if val.to_string() != idx { + return None; + } + integers.push(val); } let min = *integers.iter().min()?; let max = *integers.iter().max()?; From ebf720410bc5ab52e4666bfc01275238f2fb5fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Mon, 13 Nov 2023 11:09:59 +0100 Subject: [PATCH 2/2] add comment explaining why range syntax is not valid --- svd-rs/src/dimelement.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/svd-rs/src/dimelement.rs b/svd-rs/src/dimelement.rs index 67522f41..4f8e3637 100644 --- a/svd-rs/src/dimelement.rs +++ b/svd-rs/src/dimelement.rs @@ -170,6 +170,8 @@ impl DimElement { pub fn indexes_as_range(&self) -> Option> { let mut integers = Vec::with_capacity(self.dim as usize); for idx in self.indexes() { + // XXX: indexes that begin with leading zero are not compatible with range (`0-x`) syntax in serialization + // see https://github.com/rust-embedded/svdtools/pull/178#issuecomment-1801433808 let val = idx.parse::().ok()?; if val.to_string() != idx { return None;