Opened 20 years ago

Closed 20 years ago

#1032 closed defect (fixed)

Divide by zero error in mythfrontend information screen

Reported by: mythdev@… Owned by: cpinkham
Priority: minor Milestone: 0.19
Component: mythtv Version: head
Severity: low Keywords:
Cc: Ticket locked: no

Description

If the recorded table is empty then selecting Information Centre/System? Status/Machine? Status segfaults with a divide by zero in disk_usage_with_rec_time_kb (statusbox.cpp) - because bytesPerMin is zero.

This is caused by the first query in StatusBox::getActualRecordedBPS.

Because this is computing a value it will always return a result = NULL when the recorded table is empty - in which case query.value(0).toDouble() will return 0. (mysql docs say that is what it is supposed to do) Unfortunately query.value(0).isValid() is true and query.value(0).isNull() is false so the only fix I can think of is as below:

Index: mythtv/programs/mythfrontend/statusbox.cpp
===================================================================
--- mythtv/programs/mythfrontend/statusbox.cpp  (revision 8599)
+++ mythtv/programs/mythfrontend/statusbox.cpp  (working copy)
@@ -1063,8 +1063,13 @@
     query.prepare(querystr.arg(hostnames));

     if (query.exec() && query.isActive() && query.size() > 0 && query.next())
+    {
+        if ( query.value(0).toDouble() == 0 )
+            return;  // recorded table was empty
+
         recordingProfilesBPS[QObject::tr("average")] =
             (int)(query.value(0).toDouble());
+    }

     querystr =
         "SELECT max(filesize * 8 / "

This is at svn 8599 with mysql 4.0

Change History (2)

comment:1 Changed 20 years ago by cpinkham

Status: newassigned

comment:2 Changed 20 years ago by cpinkham

Resolution: fixed
Status: assignedclosed

(In [8610]) Prevent a divide-by-zero error in mythfrontend's status page if there are no recordings. This refernces #1032, but I did it a slightly different way by not short-cutting and returning in case we add more calculations that aren't based on the number of recordings.

Closes #1032.

Note: See TracTickets for help on using tickets.