summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-08-13 10:40:11 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2022-12-09 20:42:12 +0100
commitba2a5d693bad6d9bc9b0722fcdf8fc824eabceb4 (patch)
treece82966f4b4ed963b26094f0ff26511d86a2fe10 /tests
parentee29fbb859b681c154485dd5b012a20b953a0b41 (diff)
Fix crash on serializing default-constructed QTimeZone
The serialization code neglected to check against null. Since zones are saved either by IANA ID or in our special OffsetFromUtc format, representing an invalid zone by a string that cannot possibly be a valid IANA ID will do. Fixes: QTBUG-86019 Change-Id: I6882026403d00f8b254aab34c645f1cf8f9fcc2d Reviewed-by: Taylor Braun-Jones <taylor@braun-jones.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 14f3f419b0864944d75283a850dc0ce141feaf0e) Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
index 412f092377..59b94179f4 100644
--- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
@@ -65,6 +65,7 @@ private slots:
void isValidId_data();
void isValidId();
void malformed();
+ void serialize();
// Backend tests
void utcTest();
void icuTest();
@@ -951,6 +952,33 @@ void tst_QTimeZone::malformed()
barf.offsetFromUtc(now);
}
+void tst_QTimeZone::serialize()
+{
+ int parts = 0;
+#ifndef QT_NO_DEBUG_STREAM
+ qDebug() << QTimeZone(); // to verify no crash
+ parts++;
+#endif
+#ifndef QT_NO_DATASTREAM
+ QByteArray blob;
+ {
+ QDataStream stream(&blob, QIODevice::WriteOnly);
+ stream << QTimeZone("Europe/Oslo") << QTimeZone(420) << QTimeZone() << qint64(-1);
+ }
+ QDataStream stream(&blob, QIODevice::ReadOnly);
+ QTimeZone invalid, offset, oslo;
+ qint64 minusone;
+ stream >> oslo >> offset >> invalid >> minusone;
+ QCOMPARE(oslo, QTimeZone("Europe/Oslo"));
+ QCOMPARE(offset, QTimeZone(420));
+ QVERIFY(!invalid.isValid());
+ QCOMPARE(minusone, qint64(-1));
+ parts++;
+#endif
+ if (!parts)
+ QSKIP("No serialization enabled");
+}
+
void tst_QTimeZone::utcTest()
{
#ifdef QT_BUILD_INTERNAL