diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-06 13:52:34 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-06 13:52:34 +0530 |
commit | 0718d2a2a1f8ac16f0bbd30b520a3804e09eab41 (patch) | |
tree | e8dedc0144ce3985e3e6f0ec884cd42c5bda4586 /src | |
parent | 399391a3d72ca099b30f7bc2c0468ce845c71798 (diff) |
Fix endless loop and infinite memory consumption due to... NAN!!
Diffstat (limited to 'src')
-rw-r--r-- | src/interactive/app/bytevis.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/interactive/app/bytevis.rs b/src/interactive/app/bytevis.rs index b27da6d..70c7714 100644 --- a/src/interactive/app/bytevis.rs +++ b/src/interactive/app/bytevis.rs @@ -43,6 +43,11 @@ impl fmt::Display for DisplayByteVisualization { use ByteVisualization::*; let Self { format, percentage } = self; + let percentage = if percentage.is_nan() { + 0.0 + } else { + *percentage + }; const BAR_SIZE: usize = 10; match format { Percentage => Self::make_percentage(f, percentage), @@ -58,7 +63,7 @@ impl fmt::Display for DisplayByteVisualization { } impl DisplayByteVisualization { - fn make_bar(f: &mut fmt::Formatter, percentage: &f32, length: usize) -> Result<(), fmt::Error> { + fn make_bar(f: &mut fmt::Formatter, percentage: f32, length: usize) -> Result<(), fmt::Error> { let block_length = (length as f32 * percentage).round() as usize; for _ in 0..block_length { f.write_str(tui::symbols::block::FULL)?; @@ -68,7 +73,7 @@ impl DisplayByteVisualization { } Ok(()) } - fn make_percentage(f: &mut fmt::Formatter, percentage: &f32) -> Result<(), fmt::Error> { + fn make_percentage(f: &mut fmt::Formatter, percentage: f32) -> Result<(), fmt::Error> { write!(f, " {:>5.02}% ", percentage * 100.0) } } |