Skip to content

Commit 973a46c

Browse files
committed
svd-rs: fix write constraint check
Fixes the write constraint check to avoid a run-time panic when the bit-range width is set to `64`. Also avoids an unnecessary check, since all `u64` values will be valid.
1 parent 8194739 commit 973a46c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

svd-rs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## Unreleased
99

1010
- Add `DataType`
11+
- Fix run-time panic for write constraint check
1112

1213
## [v0.14.8] - 2024-02-13
1314

svd-rs/src/field.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,13 @@ impl FieldInfo {
336336
}
337337
}
338338

339-
if let Some(WriteConstraint::Range(constraint)) = self.write_constraint {
340-
constraint.check_range(0..2_u64.pow(self.bit_range.width))?;
339+
match self.write_constraint {
340+
// If the bit_range has its maximum width, all values will of
341+
// course fit in so we can skip validation.
342+
Some(WriteConstraint::Range(constraint)) if self.bit_range.width < 64 => {
343+
constraint.check_range(0..2_u64.pow(self.bit_range.width))?;
344+
}
345+
_ => (),
341346
}
342347
}
343348

0 commit comments

Comments
 (0)