From 07fffa60103fed42efed86f928fcec30f9d98815 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 21 Feb 2017 11:01:46 -0800 Subject: 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 --- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/auto/corelib') 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); -- cgit v1.2.3