diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-09 13:11:16 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-09 13:11:16 +0300 |
commit | 651501ea8fa1e1f0fb828efc4878c25e0befb908 (patch) | |
tree | 24092d221c3c8ef75ddeef6d49e9e9c6a0dbb656 /src | |
parent | f759b54a54c48ea46388f01c1d550e3e24f81afd (diff) |
Fix 'panic byte index is out of bounds'
Fix wrong byte index in RAM display string of RAM bar. Variable
`cutoff`'s value could surpass `mem_display`'s length.
Fixes #1
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/components/kernel.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/ui/components/kernel.rs b/src/ui/components/kernel.rs index 710454c..2534192 100644 --- a/src/ui/components/kernel.rs +++ b/src/ui/components/kernel.rs @@ -156,7 +156,7 @@ impl Component for KernelMetrics { } /* Draw CPU usage bars */ - let bar_max = (0.6 * total_cols as f32) as usize; + let bar_max = std::cmp::min((0.6 * total_cols as f32) as usize, total_cols); let old_cpu_stat = self.cpu_stat[0]; let mut boot_time: usize = 0; @@ -259,11 +259,14 @@ impl Component for KernelMetrics { let mut x = 0; /* Calculate spillover of mem_display string to available part of the bar in order to * paint it differently */ - let cutoff = if mem_display_padding + mem_display.len() > mem_bar_length { - mem_bar_length - mem_display_padding - } else { - mem_display.len() - }; + let cutoff = std::cmp::min( + mem_display.len() - 1, + if mem_display_padding + mem_display.len() > mem_bar_length { + mem_bar_length - mem_display_padding + } else { + mem_display.len() + }, + ); while x < mem_bar_length { if x == mem_display_padding { |