From 7b000b376d60d2461d0cf4320d44576a4fb33420 Mon Sep 17 00:00:00 2001 From: bsongis Date: Tue, 26 Jun 2012 20:14:12 +0000 Subject: [PATCH] Possible division per 0 --- src/frsky.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/frsky.cpp b/src/frsky.cpp index 8ea89b40a..fd0118fb1 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -791,11 +791,12 @@ void FrskyValueWithMinMax::set(uint8_t value, uint8_t unit) void frskyEvalCurrentConsumptionBoundary() { - if (g_model.frsky.currentSource == CURRENT_SOURCE_HUB) { - currentConsumptionBoundary = 3600; - } - else { - currentConsumptionBoundary = 360000L / (g_model.frsky.channels[g_model.frsky.currentSource-1].ratio << g_model.frsky.channels[g_model.frsky.currentSource-1].multiplier); + currentConsumptionBoundary = 3600; + if (g_model.frsky.currentSource > CURRENT_SOURCE_HUB) { + uint16_t divider = (g_model.frsky.channels[g_model.frsky.currentSource-1].ratio << g_model.frsky.channels[g_model.frsky.currentSource-1].multiplier); + if (divider > 5) { + currentConsumptionBoundary = 360000L / divider; + } } }