Skip to content

Commit a54d1e5

Browse files
authored
Merge pull request #241 from rust-embedded/range
fix indexes_as_range
2 parents 4680d8d + ebf7204 commit a54d1e5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

svd-rs/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
- Fix `indexes_as_range`
11+
1012
## [v0.14.3] - 2023-04-04
1113

1214
- Bump MSRV to 1.58.0

svd-rs/src/dimelement.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ impl DimElement {
170170
pub fn indexes_as_range(&self) -> Option<RangeInclusive<u32>> {
171171
let mut integers = Vec::with_capacity(self.dim as usize);
172172
for idx in self.indexes() {
173-
integers.push(idx.parse::<u32>().ok()?);
173+
// XXX: indexes that begin with leading zero are not compatible with range (`0-x`) syntax in serialization
174+
// see https://github.com/rust-embedded/svdtools/pull/178#issuecomment-1801433808
175+
let val = idx.parse::<u32>().ok()?;
176+
if val.to_string() != idx {
177+
return None;
178+
}
179+
integers.push(val);
174180
}
175181
let min = *integers.iter().min()?;
176182
let max = *integers.iter().max()?;

0 commit comments

Comments
 (0)