diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-10 16:21:49 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-19 13:56:36 +0200 |
commit | 24f5e48fba15ef1954f8c552db961b9141269c98 (patch) | |
tree | ef316927e3d301731a33e55aa0f349dabc7324e6 | |
parent | 9d242afbd01bef6f5f0455100dc8299980ae08ca (diff) |
Apply NSDMI to some internal datetime and timezone types
Although parsedRfcDateTime's clients never read utcOffset unless date
and time are valid, and never set them to anything valid without also
setting utcOffset, let's not leave it uninitialized by default.
The TZ file digester didn't actually set QTzTimeZoneCacheEntry except
when setting it to true, so let's make sure it's properly initialized
to false. The m_preZoneRule was initialized to all-zeros in one branch
of its construction, so set it to that by default so that its default
constructor leaves no member uninitialized.
These types are only constructed in parsers anyway, so the minor cost
of setting fields to zero is dwarfed by string manipulations.
Task-number: QTBUG-122619
Change-Id: I6c57fc6d33c379af3f7c6de80c4ca47e431f9d92
Reviewed-by: Mate Barany <mate.barany@qt.io>
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 2 | ||||
-rw-r--r-- | src/corelib/time/qtimezoneprivate_p.h | 8 | ||||
-rw-r--r-- | src/corelib/time/qtimezoneprivate_tz.cpp | 2 |
3 files changed, 5 insertions, 7 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 2f1f80d70d..199fe0f015 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -130,7 +130,7 @@ ParsedInt readInt(QStringView text) struct ParsedRfcDateTime { QDate date; QTime time; - int utcOffset; + int utcOffset = 0; }; static int shortDayFromName(QStringView name) diff --git a/src/corelib/time/qtimezoneprivate_p.h b/src/corelib/time/qtimezoneprivate_p.h index 3aa3658c14..53da9693ca 100644 --- a/src/corelib/time/qtimezoneprivate_p.h +++ b/src/corelib/time/qtimezoneprivate_p.h @@ -254,9 +254,9 @@ struct QTzTransitionTime Q_DECLARE_TYPEINFO(QTzTransitionTime, Q_PRIMITIVE_TYPE); struct QTzTransitionRule { - int stdOffset; - int dstOffset; - quint8 abbreviationIndex; + int stdOffset = 0; + int dstOffset = 0; + quint8 abbreviationIndex = 0; }; Q_DECLARE_TYPEINFO(QTzTransitionRule, Q_PRIMITIVE_TYPE); constexpr inline bool operator==(const QTzTransitionRule &lhs, const QTzTransitionRule &rhs) noexcept @@ -273,7 +273,7 @@ struct QTzTimeZoneCacheEntry QList<QByteArray> m_abbreviations; QByteArray m_posixRule; QTzTransitionRule m_preZoneRule; - bool m_hasDst; + bool m_hasDst = false; }; class Q_AUTOTEST_EXPORT QTzTimeZonePrivate final : public QTimeZonePrivate diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index b6a7d1418c..c046dd881d 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -884,8 +884,6 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::findEntry(const QByteArray &ianaId) // TODO: is typeList[0] always the "before zones" data ? It seems to be ... if (typeList.size()) ret.m_preZoneRule = { typeList.at(0).tz_gmtoff, 0, typeList.at(0).tz_abbrind }; - else - ret.m_preZoneRule = { 0, 0, 0 }; // Offsets are stored as total offset, want to know separate UTC and DST offsets // so find the first non-dst transition to use as base UTC Offset |