Ensure QTzTimeZonePrivate always tries a non-empty IANA ID

QTzTimeZonePrivate::init() was coping with empty and then saving the
system ID if the ID it looked up was empty. Better to have its caller
ensure it's passed the system ID in place of empty. The system ID is
always non-empty, as it falls back to "UTC" if it would otherwise have
been empty.

Change-Id: I5c74e23f01ef578de0dc1f6d558e9c8c7e65ff53
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Edward Welbourne 2020-03-31 18:16:01 +02:00
parent 276fa8383a
commit b40ac4b858

View File

@ -639,7 +639,7 @@ QTzTimeZonePrivate::QTzTimeZonePrivate()
// Create a named time zone // Create a named time zone
QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId)
{ {
init(ianaId); init(ianaId.isEmpty() ? systemTimeZoneId() : ianaId);
} }
QTzTimeZonePrivate::~QTzTimeZonePrivate() QTzTimeZonePrivate::~QTzTimeZonePrivate()
@ -852,13 +852,16 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::fetchEntry(const QByteArray &ianaId)
void QTzTimeZonePrivate::init(const QByteArray &ianaId) void QTzTimeZonePrivate::init(const QByteArray &ianaId)
{ {
// System ID defaults to UTC, so is never empty; and our callers default to
// the system ID if what they're given is empty.
Q_ASSERT(!ianaId.isEmpty());
static QTzTimeZoneCache tzCache; static QTzTimeZoneCache tzCache;
const auto &entry = tzCache.fetchEntry(ianaId); const auto &entry = tzCache.fetchEntry(ianaId);
if (entry.m_tranTimes.isEmpty() && entry.m_posixRule.isEmpty()) if (entry.m_tranTimes.isEmpty() && entry.m_posixRule.isEmpty())
return; // Invalid after all ! return; // Invalid after all !
cached_data = std::move(entry); cached_data = std::move(entry);
m_id = ianaId.isEmpty() ? systemTimeZoneId() : ianaId; m_id = ianaId;
} }
QLocale::Country QTzTimeZonePrivate::country() const QLocale::Country QTzTimeZonePrivate::country() const