catalog_shell: check and return on empty list in order to avoid division by zero

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2019-11-26 11:33:28 +01:00 committed by Dietmar Maurer
parent 4e56b2f792
commit 59bc6ad676
1 changed files with 3 additions and 0 deletions

View File

@ -431,6 +431,9 @@ impl Shell {
} }
fn print_list(list: &Vec<DirEntry>) -> Result<(), std::io::Error> { fn print_list(list: &Vec<DirEntry>) -> Result<(), std::io::Error> {
if list.is_empty() {
return Ok(());
}
let max = list let max = list
.iter() .iter()
.max_by(|x, y| x.name.len().cmp(&y.name.len())); .max_by(|x, y| x.name.len().cmp(&y.name.len()));