summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-02-21 11:01:46 -0800
committerThiago Macieira <thiago.macieira@intel.com>2017-02-24 16:17:03 +0000
commit07fffa60103fed42efed86f928fcec30f9d98815 (patch)
tree2cd8df999989120031fc56ccbe516658c9a1c663 /tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
parent4d3781b640e8fb0a04e96b2d05199247556b8d86 (diff)
QDateTime: Fix clearing the ShortData flag in setMSecsSinceEpoch
Unlike setTimeSpec, this forgot to clear the bit when detaching. So it's possible that some further use of the flags could incorrectly conclude that the data was short and then proceed to corrupt the pointer. The example from QTBUG-59061 caused this because toUTC() -> toTimeSpec() calls setMSecsSinceEpoch which left the bit set; then addDays() calls setDateTime(), which calls checkValidDateTime() and that corrupted the pointer. This problem was more visible on 32-bit systems because no QDateTime was short (except for default constructed ones), but it can happen on 64-bit with sufficiently large dates. Task-number: QTBUG-59061 Change-Id: Ibc5c715fda334a75bd2efffd14a562a375a4e69b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp')
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index e54edb490c..33844feafe 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -667,6 +667,29 @@ void tst_QDateTime::setMSecsSinceEpoch()
QCOMPARE(dt.time(), utc.time());
QCOMPARE(dt.timeSpec(), Qt::UTC);
+ {
+ QDateTime dt1 = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC);
+ QCOMPARE(dt1, utc);
+ QCOMPARE(dt1.date(), utc.date());
+ QCOMPARE(dt1.time(), utc.time());
+ QCOMPARE(dt1.timeSpec(), Qt::UTC);
+ }
+ {
+ QDateTime dt1(utc.date(), utc.time(), Qt::UTC);
+ QCOMPARE(dt1, utc);
+ QCOMPARE(dt1.date(), utc.date());
+ QCOMPARE(dt1.time(), utc.time());
+ QCOMPARE(dt1.timeSpec(), Qt::UTC);
+ }
+ {
+ // used to fail to clear the ShortData bit, causing corruption
+ QDateTime dt1 = dt.addDays(0);
+ QCOMPARE(dt1, utc);
+ QCOMPARE(dt1.date(), utc.date());
+ QCOMPARE(dt1.time(), utc.time());
+ QCOMPARE(dt1.timeSpec(), Qt::UTC);
+ }
+
if (zoneIsCET) {
QCOMPARE(dt.toLocalTime(), cet);