From 40e49bffe4e9ecd682eb746deafd68bd088dd415 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Fri, 17 May 2024 18:26:37 +0300 Subject: [PATCH] fix: Overflow in utils::vault_by_index_or_name function Fixes: https://git.4rs.nl/awiteb/lprs/issues/48 --- src/utils.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index 61b49ee..9551236 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -221,7 +221,9 @@ pub fn vault_by_index_or_name<'a>( let parsed_index = index_or_name.parse::(); 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()