From e3c831dc558de7e83c81fe09644db18013d5dd65 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Feb 2024 15:24:58 +0100 Subject: [PATCH] QOperatingSystemVersion: fix UB (invalid static_cast) When the QOSVBase we're constructing from isn't an actual QOSVUnexported, the cast from QOSVBase to QOSVUnexported is invalid. Instead of casting, add an QOSVUnexported(QOSVBase) ctor and just call that. Amends 215677818470e48e9090d7ae4411e1fea62207b8. Pick-to: 6.7 6.6 Change-Id: I7352a044b62086585f1b036433f9b8779c77ac9d Reviewed-by: Volker Hilsheimer Reviewed-by: Qt CI Bot --- src/corelib/global/qoperatingsystemversion.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qoperatingsystemversion.h b/src/corelib/global/qoperatingsystemversion.h index a11c90072fc..ef032b6532f 100644 --- a/src/corelib/global/qoperatingsystemversion.h +++ b/src/corelib/global/qoperatingsystemversion.h @@ -111,6 +111,8 @@ class QOperatingSystemVersionUnexported : public QOperatingSystemVersionBase { public: using QOperatingSystemVersionBase::QOperatingSystemVersionBase; + constexpr QOperatingSystemVersionUnexported(QOperatingSystemVersionBase other) noexcept + : QOperatingSystemVersionBase(other) {} #else class QOperatingSystemVersion : public QOperatingSystemVersionBase { @@ -226,7 +228,7 @@ public: static constexpr QOperatingSystemVersionBase MacOSVentura { QOperatingSystemVersionBase::MacOS, 13, 0 }; constexpr QOperatingSystemVersion(const QOperatingSystemVersionBase &osversion) - : QOperatingSystemVersionUnexported(static_cast(osversion)) {} + : QOperatingSystemVersionUnexported(osversion) {} constexpr QOperatingSystemVersion(OSType osType, int vmajor, int vminor = -1, int vmicro = -1) : QOperatingSystemVersionUnexported(QOperatingSystemVersionBase::OSType(osType), vmajor, vminor,