diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-11-07 17:17:59 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-11-30 20:20:10 +0000 |
commit | 35176c22896a6c633408907e8113c3f1b9a846b0 (patch) | |
tree | b24d177879be03b07246feb7d5c9208b651883e9 | |
parent | 68bcccac228b73c54137304718c3c92460bc1f4b (diff) |
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 <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/tools/qtimezoneprivate.cpp | 4 |
1 files 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; |