From c1f40b8ebb49ddd617d03ca5875596dab6df8c77 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 23 Oct 2018 14:09:44 -0400 Subject: [PATCH] Fix OSD time remaining division by zero If the current sensor wasn't configured (or the mahDrawn was still zero) then there would be a division by zero error in the remaining time OSD element calculation. Rearranged the logic to prevent. --- src/main/io/osd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 4ce33c06cd..07b26c4576 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -604,13 +604,13 @@ static bool osdDrawSingleElement(uint8_t item) case OSD_REMAINING_TIME_ESTIMATE: { const int mAhDrawn = getMAhDrawn(); - const int remaining_time = (int)((osdConfig()->cap_alarm - mAhDrawn) * ((float)flyTime) / mAhDrawn); - if (mAhDrawn < 0.1 * osdConfig()->cap_alarm) { + if (mAhDrawn <= 0.1 * osdConfig()->cap_alarm) { // also handles the mAhDrawn == 0 condition tfp_sprintf(buff, "--:--"); } else if (mAhDrawn > osdConfig()->cap_alarm) { tfp_sprintf(buff, "00:00"); } else { + const int remaining_time = (int)((osdConfig()->cap_alarm - mAhDrawn) * ((float)flyTime) / mAhDrawn); osdFormatTime(buff, OSD_TIMER_PREC_SECOND, remaining_time); } break;