From 7db6aa4395541288ba790e5acdfad4a5cc5d4cd2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 31 Mar 2022 18:47:04 +0200 Subject: [PATCH] Fix overflow issue discovered by MSVC in C++20 mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 74eddd5bf0672db4edd190aefd813bcf7eb26df4 Done-with: Giuseppe D'Angelo Fixes: QTBUG-102157 Pick-to: 6.3 Change-Id: I25e358070907f22d9e4fb0030fa82ec290c7a730 Reviewed-by: Giuseppe D'Angelo Reviewed-by: MÃ¥rten Nordheim --- src/corelib/time/qdatetime.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 89a0dc0324..b168c91ec8 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -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;