summaryrefslogtreecommitdiffstats
path: root/src/plugins/canbus/peakcan
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2016-09-16 06:11:23 +0200
committerAndré Hartmann <aha_1980@gmx.de>2016-09-16 07:23:46 +0000
commitbb75d3d4a4e4b7b1efb383d755e05e5f3623572c (patch)
tree587c136beebd4cd9d0faf7650c17d7a6521c95fd /src/plugins/canbus/peakcan
parentf9496a178bb713221091c0f436484932f991fc71 (diff)
PeakCAN: Avoid overflows on timestamp calculation
While the formula itself is correct, there is a chance of getting wrong values due to limited data types. Found after a hint from H.Mueller in the Peak Forum: http://www.peak-system.com/forum/viewtopic.php?f=41&t=1238 Change-Id: I0f3036c5d694bee7cc8d3fd54e206545b71344b7 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/plugins/canbus/peakcan')
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp
index c245462..9598003 100644
--- a/src/plugins/canbus/peakcan/peakcanbackend.cpp
+++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp
@@ -440,8 +440,8 @@ void PeakCanBackendPrivate::canReadNotification()
}
QCanBusFrame frame(message.ID, QByteArray(reinterpret_cast<const char *>(message.DATA), int(message.LEN)));
- const quint64 millis = timestamp.millis + 0xFFFFFFFFU * timestamp.millis_overflow;
- const quint64 micros = 1000 * (millis % 1000) + timestamp.micros;
+ const quint64 millis = timestamp.millis + Q_UINT64_C(0xFFFFFFFF) * timestamp.millis_overflow;
+ const quint64 micros = Q_UINT64_C(1000) * (millis % 1000) + timestamp.micros;
frame.setTimeStamp(QCanBusFrame::TimeStamp(millis / 1000, micros));
frame.setExtendedFrameFormat(message.MSGTYPE & PCAN_MESSAGE_EXTENDED);
frame.setFrameType((message.MSGTYPE & PCAN_MESSAGE_RTR) ? QCanBusFrame::RemoteRequestFrame : QCanBusFrame::DataFrame);