Fix overflow issue discovered by MSVC in C++20 mode
In setMSecsSinceEpoch(), when epochMSecsToLocalTime() fails (e.g. when
msecs is near one end of time and the offset being added causes
overflow), the call to setDateTime(d, ...) is bypassed so the d-ptr is
not updated and getStatus(d) returns the status prior to the function
call. The new status being prepared by the function should thus not be
updated to getStatus(d) unless setDateTime(d, ...) was called.
This amends commit 74eddd5bf0
Done-with: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Fixes: QTBUG-102157
Pick-to: 6.3
Change-Id: I25e358070907f22d9e4fb0030fa82ec290c7a730
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
d9ae822e05
commit
7db6aa4395
@ -4149,9 +4149,10 @@ void QDateTime::setMSecsSinceEpoch(qint64 msecs)
|
||||
if (spec == Qt::LocalTime) {
|
||||
QDate dt;
|
||||
QTime tm;
|
||||
if (QDateTimePrivate::epochMSecsToLocalTime(msecs, &dt, &tm, &dst))
|
||||
if (QDateTimePrivate::epochMSecsToLocalTime(msecs, &dt, &tm, &dst)) {
|
||||
setDateTime(d, dt, tm);
|
||||
status = getStatus(d);
|
||||
status = getStatus(d);
|
||||
} // else leave status marked invalid.
|
||||
if ((status & QDateTimePrivate::ValidDate) && (status & QDateTimePrivate::ValidTime)) {
|
||||
local = getMSecs(d);
|
||||
offsetFromUtc = (local - msecs) / MSECS_PER_SEC;
|
||||
|
Loading…
Reference in New Issue
Block a user