From 0718d2a2a1f8ac16f0bbd30b520a3804e09eab41 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 6 Jun 2019 13:52:34 +0530 Subject: Fix endless loop and infinite memory consumption due to... NAN!! --- src/interactive/app/bytevis.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') 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) } } -- cgit v1.2.3