Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13013 closed Patch - Bug Fix (fixed)

Correct plist.cpp ParseBinaryDate processing

Reported by: Gary Buhrmaster <gary.buhrmaster@…> Owned by: Stuart Auchterlonie
Priority: minor Milestone: 29.0
Component: MythTV - General Version: Master Head
Severity: medium Keywords:
Cc: Ticket locked: no

Description

Correct plist.cpp ParseBinaryDate? processing

gcc correctly warns about a bare time.addMSecs (it returns a QTime):

plist.cpp: In member function ‘QVariant PList::ParseBinaryDate(quint8*)’:
plist.cpp:467:30: warning: ignoring return value of ‘QTime QTime::addMSecs(int) const’, declared with attribute warn_unused_result [-Wunused-result]
     time.addMSecs(msec % 1000);
                              ^
In file included from /usr/include/qt5/QtCore/QDateTime:1:0,
                 from plist.cpp:32:
/usr/include/qt5/QtCore/qdatetime.h:178:11: note: declared here
     QTime addMSecs(int ms) const Q_REQUIRED_RESULT;
           ^~~~~~~~

If I understand the code correctly, the intent is to add in the msec offset value into the converted time, with the gyrations needed due to the limitation of the older QDateTime fromTime_t member (seconds only).

Note that in Qt 5.8, QDateTime::fromTime_t is depcrecated, and since Qt 5.2, a new function QDateTime::fromMSecsSinceEpoch exists that appears to do what was originally desired.

Kill the warning (bug), and prepare for the future, with the following proposed patch:

WARNING: Compile tested only (caveat emptor).

diff --git a/mythtv/libs/libmythbase/plist.cpp b/mythtv/libs/libmythbase/plist.cpp
index c21a776..9aba9b0 100644
--- a/mythtv/libs/libmythbase/plist.cpp
+++ b/mythtv/libs/libmythbase/plist.cpp
@@ -459,16 +459,13 @@ QVariant PList::ParseBinaryDate(quint8 *data)
     quint64 count = GetBinaryCount(&data);
     if (count != 3)
         return result;
 
     convert_float(data, 8);
     quint64 msec = *((double*)data) * 1000.0f;
-    result = QDateTime::fromTime_t(msec / 1000);
-    QTime time = result.time();
-    time.addMSecs(msec % 1000);
-    result.setTime(time);
+    result = QDateTime::fromMSecsSinceEpoch(msec, Qt::UTC);
     LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("Date: %1").arg(result.toString(Qt::ISODate)));
     return QVariant(result);
 }
 
 QVariant PList::ParseBinaryData(quint8 *data)
 {

Change History (2)

comment:1 Changed 7 years ago by Gary Buhrmaster <gary.buhrmaster@…>

Owner: set to Gary Buhrmaster <gary.buhrmaster@…>
Resolution: fixed
Status: newclosed

In f593e239acf14b957c0b41ae2b6b195eb1b104bd/mythtv:

Fixes #13013 - Remove warning and use a Qt method which achieves the same result

This is a reworking of f37b2a29e2f8a3f1e0ccf5b1c1d269bcbdbfe2e7
which uses Qt functions which better match the intent of the code.

Signed-off-by: Stuart Auchterlonie <stuarta@…>

comment:2 Changed 7 years ago by Stuart Auchterlonie

Milestone: unknown29.0
Owner: changed from Gary Buhrmaster <gary.buhrmaster@…> to Stuart Auchterlonie
Note: See TracTickets for help on using tickets.