change(validator): add AddressOutofRange error

This commit is contained in:
Wataru Otsubo 2025-02-22 23:52:45 +09:00
parent 06a5429583
commit 76595d0c92

View file

@ -24,6 +24,8 @@ pub enum ValidationError {
existing_name: String,
new_name: String,
},
#[error("address 0x{address:08x} is out of range: \"{name}\"")]
AddressOutofRange { address: u32, name: String },
#[error("unsupported structure: {msg}")]
UnsupportedStructure { msg: &'static str },
}
@ -105,9 +107,16 @@ impl Validate for Register {
};
for id in 0..len {
let addr = addr + id * offset;
let regmap: &mut Option<_> = mapping
.get_mut::<usize>(addr.try_into().unwrap())
.expect("index of mapping out of range");
let regmap: &mut Option<_> = match mapping.get_mut::<usize>(addr.try_into().unwrap()) {
Some(regmap) => regmap,
None => {
errors.push(ValidationError::AddressOutofRange {
address: addr,
name: self.name.clone(),
});
continue;
}
};
if let Some(old) = regmap {
let existing_name = {
let mut path = old.0.clone();