From bb75d3d4a4e4b7b1efb383d755e05e5f3623572c Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Fri, 16 Sep 2016 06:11:23 +0200 Subject: 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 Reviewed-by: Marc Mutz Reviewed-by: Alex Blasche --- src/plugins/canbus/peakcan/peakcanbackend.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/canbus/peakcan/peakcanbackend.cpp') 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(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); -- cgit v1.2.3