From 52b5e9b76663fa7b43da1466fb2678d6b18d86b2 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 23 Feb 2021 14:38:11 +0100 Subject: Assert that either both or neither pointer are nullptr If called by QMetaType::canConvert with two nullptr values, the QMETATYPE_CONVERTER_ASSIGN macro will expand to code dereferencing both 'to' and 'from' pointers. Assert that others callers provide two valid pointers. Fixes static analyzer warning 02dc34cc2ad1d4c3c6e55b44e08983f2 Pick-to: 6.1 Change-Id: I24de914faa25dc7cb1da5eae09a125506caac389 Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qmetatype.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 8ee37212ee..bb4090129f 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -857,8 +857,12 @@ static const struct : QMetaTypeModuleHelper { Q_ASSERT(fromTypeId != toTypeId); + // canConvert calls with two nullptr bool onlyCheck = (from == nullptr && to == nullptr); + // other callers must provide two valid pointers + Q_ASSERT(onlyCheck || (bool(from) && bool(to))); + using Char = char; using SChar = signed char; using UChar = unsigned char; @@ -2159,12 +2163,18 @@ static bool convertQObject(QMetaType fromType, const void *from, QMetaType toTyp Converts the object at \a from from \a fromTypeId to the preallocated space at \a to typed \a toTypeId. Returns \c true, if the conversion succeeded, otherwise false. + + Both \a from and \a to have to be valid pointers. + \since 5.2 */ /*! Converts the object at \a from from \a fromType to the preallocated space at \a to typed \a toType. Returns \c true, if the conversion succeeded, otherwise false. + + Both \a from and \a to have to be valid pointers. + \since 5.2 */ bool QMetaType::convert(QMetaType fromType, const void *from, QMetaType toType, void *to) -- cgit v1.2.3