From bd1a2b2514ce566ce0d07a18494f24faa4259c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Fri, 15 Sep 2023 16:52:59 +0200 Subject: [PATCH] Fixed potential division by zero in FIFO Happened because somewhere in my data there was a 0 fee set, which should not cause any issues. --- src/fifo.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fifo.rs b/src/fifo.rs index c760951..827e605 100644 --- a/src/fifo.rs +++ b/src/fifo.rs @@ -32,6 +32,10 @@ fn gains<'a>(holdings: &mut HashMap<&'a str, VecDeque>, timestamp: NaiveD let mut capital_gains: Vec = Vec::new(); let mut sold_quantity = outgoing.quantity; + if sold_quantity.is_zero() { + return Ok(capital_gains); + } + let sold_unit_price = incoming_fiat / sold_quantity; while let Some(holding) = currency_holdings.front_mut() {