Skip to content

Commit 66f28dd

Browse files
committed
domains: clean up error checking
Signed-off-by: Krishnan Winter <krishnan.winter@unsw.edu.au>
1 parent aab4275 commit 66f28dd

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

tool/microkit/src/sdf.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,35 +2190,26 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
21902190

21912191
// Make sure we account for the shift when checking if the length of the
21922192
// schedule is valid and if the start index is valid.
2193-
let mut dom_shift = 0;
2194-
if dom_sched.domain_idx_shift.is_some() {
2195-
dom_shift = dom_sched.domain_idx_shift.unwrap();
2196-
}
2193+
let dom_shift = dom_sched.domain_idx_shift.unwrap_or(0);
2194+
let dom_start_idx = dom_sched.domain_start_idx.unwrap_or(0);
2195+
let schedule_len = dom_sched.schedule.len() as u64;
21972196

2198-
if dom_sched.domain_start_idx.is_some() &&
2199-
dom_sched.domain_start_idx.unwrap() >= dom_sched.schedule.len() as u64 {
2200-
return Err(format!(
2201-
"Error: Domain index of '{}' exceeds domain schedule length '{}'. NOTE: Domain start index starts at 0.",
2202-
dom_sched.domain_start_idx.unwrap(),
2203-
dom_sched.schedule.len(),
2204-
))
2205-
}
2206-
2207-
if dom_sched.domain_start_idx.is_some() &&
2208-
dom_sched.domain_start_idx.unwrap() + dom_shift >= config.num_domain_schedules
2209-
{
2197+
// Checking start index against the length of the user defined schedule
2198+
if dom_start_idx >= schedule_len {
22102199
return Err(format!(
2211-
"Error: Setting domain start index to '{}' when max schedule length is '{}'.",
2200+
"Error: Domain index of '{}' is out of bounds for domain schedule length '{}'. Note that the schedule is 0 indexed.",
22122201
dom_sched.domain_start_idx.unwrap(),
2213-
dom_sched.schedule.len()
2202+
schedule_len
22142203
))
22152204
}
22162205

2217-
let schedule_len: u64 = dom_sched.schedule.len() as u64;
2218-
if schedule_len + dom_shift > config.num_domain_schedules {
2206+
// Make sure our schedule length, including the shift, is in bounds of
2207+
// the kernel configured max number of schedules.
2208+
if schedule_len + dom_shift >= config.num_domain_schedules {
22192209
return Err(format!(
2220-
"Error: Schedule length '{}' exceeds max schedule length '{}'.",
2210+
"Error: Schedule length '{}' with shift of '{}' exceeds max schedule length '{}'.",
22212211
schedule_len,
2212+
dom_shift,
22222213
config.num_domain_schedules,
22232214
))
22242215
}

0 commit comments

Comments
 (0)