From 35176c22896a6c633408907e8113c3f1b9a846b0 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 7 Nov 2017 17:17:59 +0100 Subject: Avoid underflow on arithmetic with possibly-first transition times A transition time may represent the beginning of time; as such, arithmetic on it might underflow, e.g. on adding a negative zone offset to compare with a given time. So move the arithmetic to the other side of the comparison in such cases. Change-Id: I1697a03ebf74679ff86059664dd2b173b9c4c367 Reviewed-by: Thiago Macieira --- src/corelib/tools/qtimezoneprivate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp index e45dd48de0..1a5135f103 100644 --- a/src/corelib/tools/qtimezoneprivate.cpp +++ b/src/corelib/tools/qtimezoneprivate.cpp @@ -329,7 +329,7 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs, // Only around the transition times might we need another. Data tran = previousTransition(forLocalMSecs - sixteenHoursInMSecs); Q_ASSERT(forLocalMSecs < 0 || // Pre-epoch TZ info may be unavailable - forLocalMSecs >= tran.atMSecsSinceEpoch + tran.offsetFromUtc * 1000); + forLocalMSecs - tran.offsetFromUtc * 1000 >= tran.atMSecsSinceEpoch); Data nextTran = nextTransition(tran.atMSecsSinceEpoch); /* Now walk those forward until they bracket forLocalMSecs with transitions. @@ -363,7 +363,7 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs, fail life's tricky. */ Q_ASSERT(forLocalMSecs < 0 - || forLocalMSecs > tran.atMSecsSinceEpoch + tran.offsetFromUtc * 1000); + || forLocalMSecs - tran.offsetFromUtc * 1000 > tran.atMSecsSinceEpoch); const qint64 nextStart = nextTran.atMSecsSinceEpoch; // Work out the UTC values it might make sense to return: nextTran.atMSecsSinceEpoch = forLocalMSecs - nextTran.offsetFromUtc * 1000; -- cgit v1.2.3