Skip to content

Commit 0930340

Browse files
author
Tom Dohrmann
committed
use u8 instead of usize for slice
1 parent c4ceb71 commit 0930340

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/structures/idt.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -458,25 +458,21 @@ impl InterruptDescriptorTable {
458458
}
459459
}
460460

461-
/// Returns a normalized and ranged check slice range from a RangeBounds trait object
461+
/// Returns a normalized and ranged check slice range from a RangeBounds trait object.
462462
///
463-
/// Panics if range is outside the range of user interrupts (i.e. greater than 255) or if the entry is an
464-
/// exception
465-
fn condition_slice_bounds(&self, bounds: impl RangeBounds<usize>) -> (usize, usize) {
463+
/// Panics if the entry is an exception.
464+
fn condition_slice_bounds(&self, bounds: impl RangeBounds<u8>) -> (usize, usize) {
466465
let lower_idx = match bounds.start_bound() {
467-
Included(start) => *start,
468-
Excluded(start) => *start + 1,
466+
Included(start) => (*start as usize),
467+
Excluded(start) => (*start as usize) + 1,
469468
Unbounded => 0,
470469
};
471470
let upper_idx = match bounds.end_bound() {
472-
Included(end) => *end + 1,
473-
Excluded(end) => *end,
471+
Included(end) => (*end as usize) + 1,
472+
Excluded(end) => (*end as usize),
474473
Unbounded => 256,
475474
};
476475

477-
if lower_idx > 256 || upper_idx > 256 {
478-
panic!("Index out of range [{}..{}]", lower_idx, upper_idx);
479-
}
480476
if lower_idx < 32 {
481477
panic!("Cannot return slice from traps, faults, and exception handlers");
482478
}
@@ -485,20 +481,18 @@ impl InterruptDescriptorTable {
485481

486482
/// Returns slice of IDT entries with the specified range.
487483
///
488-
/// Panics if range is outside the range of user interrupts (i.e. greater than 255) or if the entry is an
489-
/// exception
484+
/// Panics if the entry is an exception.
490485
#[inline]
491-
pub fn slice(&self, bounds: impl RangeBounds<usize>) -> &[Entry<HandlerFunc>] {
486+
pub fn slice(&self, bounds: impl RangeBounds<u8>) -> &[Entry<HandlerFunc>] {
492487
let (lower_idx, upper_idx) = self.condition_slice_bounds(bounds);
493488
&self.interrupts[(lower_idx - 32)..(upper_idx - 32)]
494489
}
495490

496491
/// Returns a mutable slice of IDT entries with the specified range.
497492
///
498-
/// Panics if range is outside the range of user interrupts (i.e. greater than 255) or if the entry is an
499-
/// exception
493+
/// Panics if the entry is an exception.
500494
#[inline]
501-
pub fn slice_mut(&mut self, bounds: impl RangeBounds<usize>) -> &mut [Entry<HandlerFunc>] {
495+
pub fn slice_mut(&mut self, bounds: impl RangeBounds<u8>) -> &mut [Entry<HandlerFunc>] {
502496
let (lower_idx, upper_idx) = self.condition_slice_bounds(bounds);
503497
&mut self.interrupts[(lower_idx - 32)..(upper_idx - 32)]
504498
}

0 commit comments

Comments
 (0)