Check for "data not available" responses from QTimeZonePrivate

A couple of code-paths didn't check validity of the data they got back
from QDTP, leading to assertion failures later.

Change-Id: I37d5fbcbc630832d7f438feb9dd069889ed26709
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
This commit is contained in:
Edward Welbourne 2024-07-25 18:46:16 +02:00
parent 7e256d74b3
commit d41ba9d77d
2 changed files with 12 additions and 4 deletions

View File

@ -2824,11 +2824,13 @@ QDateTimePrivate::ZoneState QDateTimePrivate::expressUtcAsLocal(qint64 utcMSecs)
#if QT_CONFIG(timezone) // Use the system time-zone. #if QT_CONFIG(timezone) // Use the system time-zone.
if (const auto sys = QTimeZone::systemTimeZone(); sys.isValid()) { if (const auto sys = QTimeZone::systemTimeZone(); sys.isValid()) {
result.offset = sys.d->offsetFromUtc(utcMSecs); result.offset = sys.d->offsetFromUtc(utcMSecs);
if (qAddOverflow(utcMSecs, result.offset * MSECS_PER_SEC, &result.when)) if (result.offset != QTimeZonePrivate::invalidSeconds()) {
if (qAddOverflow(utcMSecs, result.offset * MSECS_PER_SEC, &result.when))
return result;
result.dst = sys.d->isDaylightTime(utcMSecs) ? DaylightTime : StandardTime;
result.valid = true;
return result; return result;
result.dst = sys.d->isDaylightTime(utcMSecs) ? DaylightTime : StandardTime; }
result.valid = true;
return result;
} }
#endif // timezone #endif // timezone

View File

@ -341,6 +341,12 @@ QDateTimePrivate::ZoneState QTimeZonePrivate::stateAtZoneTime(
Q_ASSERT(recent < imminent && seventeenHoursInMSecs < imminent - recent + 1); Q_ASSERT(recent < imminent && seventeenHoursInMSecs < imminent - recent + 1);
const Data past = data(recent), future = data(imminent); const Data past = data(recent), future = data(imminent);
if (future.atMSecsSinceEpoch == invalidMSecs()
&& past.atMSecsSinceEpoch == invalidMSecs()) {
// Failed to get any useful data near this time: apparently out of range
// for the backend.
return { forLocalMSecs };
}
// > 99% of the time, past and future will agree: // > 99% of the time, past and future will agree:
if (Q_LIKELY(past.offsetFromUtc == future.offsetFromUtc if (Q_LIKELY(past.offsetFromUtc == future.offsetFromUtc
&& past.standardTimeOffset == future.standardTimeOffset && past.standardTimeOffset == future.standardTimeOffset