From c88d2b0fcd02b2125ddf6997d6f9d3de466cbe07 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 26 Aug 2022 10:02:39 +0200 Subject: [PATCH] Copy or check ShortData rather than pointer in more places This follows-up on commit 4d24fcd3e1dce6c56d9fc70ee386dcc8aa552ef6 - when ShortData is bigger than a pointer (on 32-bit systems, when using 64-bit ShortData), copying d isn't sufficient; data must be copied. Likewise, comparing d to check for equality is insufficient when isShort(), as the other may also be short and differ in the more significant bytes. Change-Id: I49c0cf33727b8b43436cf0e3f57f602e83226885 Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetime.cpp | 8 ++++---- src/corelib/time/qdatetime.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index dcb9896d685..6bed609f463 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -3016,7 +3016,7 @@ inline QDateTime::Data::Data(Qt::TimeSpec spec) } inline QDateTime::Data::Data(const Data &other) noexcept - : d(other.d) + : data(other.data) { if (!isShort()) { // check if we could shrink @@ -3033,17 +3033,17 @@ inline QDateTime::Data::Data(const Data &other) noexcept } inline QDateTime::Data::Data(Data &&other) noexcept - : d(other.d) + : data(other.data) { // reset the other to a short state Data dummy; Q_ASSERT(dummy.isShort()); - other.d = dummy.d; + other.data = dummy.data; } inline QDateTime::Data &QDateTime::Data::operator=(const Data &other) noexcept { - if (d == other.d) + if (isShort() ? data == other.data : d == other.d) return *this; auto x = d; diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h index a2f6198d08c..3cef349bd82 100644 --- a/src/corelib/time/qdatetime.h +++ b/src/corelib/time/qdatetime.h @@ -266,6 +266,8 @@ class Q_CORE_EXPORT QDateTime #if Q_BYTE_ORDER == Q_BIG_ENDIAN quintptr status : 8; #endif + friend constexpr bool operator==(const ShortData &lhs, const ShortData &rhs) + { return lhs.status == rhs.status && lhs.msecs == rhs.msecs; } }; union Data {