From f86a7ee0dfb22b5a14fc8d8f2e3907f7d1bc8fda Mon Sep 17 00:00:00 2001 From: David Hampton Date: Sat, 25 Jun 2022 23:55:35 -0400 Subject: [PATCH] Protect ProgramInfo::CalculateRecordedProgress against divide by zero. Refs #596. --- mythtv/libs/libmyth/programinfo.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mythtv/libs/libmyth/programinfo.cpp b/mythtv/libs/libmyth/programinfo.cpp index 51ac97528c4..e03baff70cf 100644 --- a/mythtv/libs/libmyth/programinfo.cpp +++ b/mythtv/libs/libmyth/programinfo.cpp @@ -6375,23 +6375,21 @@ uint64_t ProgramInfo::GetFilesize(void) const void ProgramInfo::CalculateRecordedProgress() { + m_recordedPercent = -1; if (m_recStatus != RecStatus::Recording) - { - m_recordedPercent = -1; return; - } QDateTime startTime = m_recStartTs; QDateTime now = MythDate::current(); if (now < startTime) - { - m_recordedPercent = -1; return; - } QDateTime endTime = m_recEndTs; int current = startTime.secsTo(now); int duration = startTime.secsTo(endTime); + if (duration < 1) + return; + m_recordedPercent = std::clamp(current * 100 / duration, 0, 100); LOG(VB_GUI, LOG_DEBUG, QString("%1 recorded percent %2/%3 = %4%") .arg(m_title).arg(current).arg(duration).arg(m_recordedPercent));