fix: replace manual zero-guarded divisions with checked_div
This commit is contained in:
+9
-15
@@ -133,11 +133,9 @@ pub fn per_core_handle_scrollbar_mouse(
|
|||||||
}
|
}
|
||||||
let thumb_len = (track * view).div_ceil(total).max(1).min(track);
|
let thumb_len = (track * view).div_ceil(total).max(1).min(track);
|
||||||
let top_for_offset = |off: usize| -> usize {
|
let top_for_offset = |off: usize| -> usize {
|
||||||
if max_off == 0 {
|
((track - thumb_len) * off + max_off / 2)
|
||||||
0
|
.checked_div(max_off)
|
||||||
} else {
|
.unwrap_or(0)
|
||||||
((track - thumb_len) * off + max_off / 2) / max_off
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let thumb_top = top_for_offset(offset);
|
let thumb_top = top_for_offset(offset);
|
||||||
|
|
||||||
@@ -190,11 +188,9 @@ pub fn per_core_handle_scrollbar_mouse(
|
|||||||
// Inverse mapping top -> offset
|
// Inverse mapping top -> offset
|
||||||
if track > thumb_len {
|
if track > thumb_len {
|
||||||
let denom = track - thumb_len;
|
let denom = track - thumb_len;
|
||||||
offset = if max_off == 0 {
|
offset = (new_top * max_off + denom / 2)
|
||||||
0
|
.checked_div(denom)
|
||||||
} else {
|
.unwrap_or(0);
|
||||||
(new_top * max_off + denom / 2) / denom
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
@@ -411,11 +407,9 @@ pub fn draw_per_core_bars(
|
|||||||
let max_off = total.saturating_sub(view);
|
let max_off = total.saturating_sub(view);
|
||||||
|
|
||||||
let thumb_len = (track * view).div_ceil(total).max(1).min(track);
|
let thumb_len = (track * view).div_ceil(total).max(1).min(track);
|
||||||
let thumb_top = if max_off == 0 {
|
let thumb_top = ((track - thumb_len) * offset + max_off / 2)
|
||||||
0
|
.checked_div(max_off)
|
||||||
} else {
|
.unwrap_or(0);
|
||||||
((track - thumb_len) * offset + max_off / 2) / max_off
|
|
||||||
};
|
|
||||||
|
|
||||||
// Build lines: top arrow, track (with thumb), bottom arrow
|
// Build lines: top arrow, track (with thumb), bottom arrow
|
||||||
let mut lines: Vec<Line> = Vec::with_capacity(scroll_area.height as usize);
|
let mut lines: Vec<Line> = Vec::with_capacity(scroll_area.height as usize);
|
||||||
|
|||||||
@@ -307,11 +307,9 @@ pub fn draw_top_processes(f: &mut ratatui::Frame<'_>, area: Rect, params: Proces
|
|||||||
let max_off = total.saturating_sub(view);
|
let max_off = total.saturating_sub(view);
|
||||||
|
|
||||||
let thumb_len = (track * view).div_ceil(total).max(1).min(track);
|
let thumb_len = (track * view).div_ceil(total).max(1).min(track);
|
||||||
let thumb_top = if max_off == 0 {
|
let thumb_top = ((track - thumb_len) * offset + max_off / 2)
|
||||||
0
|
.checked_div(max_off)
|
||||||
} else {
|
.unwrap_or(0);
|
||||||
((track - thumb_len) * offset + max_off / 2) / max_off
|
|
||||||
};
|
|
||||||
|
|
||||||
// Build lines: top arrow, track (with thumb), bottom arrow
|
// Build lines: top arrow, track (with thumb), bottom arrow
|
||||||
let mut lines: Vec<Line> = Vec::with_capacity(scroll_area.height as usize);
|
let mut lines: Vec<Line> = Vec::with_capacity(scroll_area.height as usize);
|
||||||
|
|||||||
Reference in New Issue
Block a user