Skip to content

Commit c1d539a

Browse files
committed
Use saturating_sub to prevent underflow
Signed-off-by: Joe Richey <[email protected]>
1 parent ccfd122 commit c1d539a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/structures/gdt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ impl GlobalDescriptorTable {
101101
pub fn add_entry(&mut self, entry: Descriptor) -> SegmentSelector {
102102
let index = match entry {
103103
Descriptor::UserSegment(value) => {
104-
if self.len > self.table.len() - 1 {
104+
if self.len > self.table.len().saturating_sub(1) {
105105
panic!("GDT full")
106106
}
107107
self.push(value)
108108
}
109109
Descriptor::SystemSegment(value_low, value_high) => {
110-
if self.len > self.table.len() - 2 {
110+
if self.len > self.table.len().saturating_sub(2) {
111111
panic!("GDT requires two free spaces to hold a SystemSegment")
112112
}
113113
let index = self.push(value_low);

0 commit comments

Comments
 (0)