From 84577ce2c20fd6da30cfa935693850ffbdaebda4 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 14 Jul 2022 08:40:49 +1200 Subject: [PATCH] battery: skip charge estimation if N cells is 0 This triggers the undefined behaviour fuzzer, so let's try to fix it. Signed-off-by: Julian Oes --- src/lib/battery/battery.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/battery/battery.cpp b/src/lib/battery/battery.cpp index 122b4e69ba..4408754d1a 100644 --- a/src/lib/battery/battery.cpp +++ b/src/lib/battery/battery.cpp @@ -206,6 +206,10 @@ void Battery::sumDischarged(const hrt_abstime ×tamp, float current_a) float Battery::calculateStateOfChargeVoltageBased(const float voltage_v, const float current_a) { + if (_params.n_cells == 0) { + return -1.0f; + } + // remaining battery capacity based on voltage float cell_voltage = voltage_v / _params.n_cells;