fix: Overflow in utils::vault_by_index_or_name function

Fixes: #48
This commit is contained in:
Awiteb 2024-05-17 18:26:37 +03:00
parent 7f8e80c645
commit 40e49bffe4
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -221,7 +221,9 @@ pub fn vault_by_index_or_name<'a>(
let parsed_index = index_or_name.parse::<usize>();
let Some((index, vault)) = (if let Ok(index) = parsed_index {
vaults.get_mut(index - 1).map(|v| (index, v))
index
.checked_sub(1)
.and_then(|zeroindex| vaults.get_mut(zeroindex).map(|v| (index, v)))
} else {
vaults
.iter_mut()