diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-02-23 14:38:11 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-02-24 11:51:47 +0100 |
commit | 52b5e9b76663fa7b43da1466fb2678d6b18d86b2 (patch) | |
tree | 19cfc6bddc28d76e051a53e9d60d0913e2679452 /src/corelib/kernel/qmetatype.cpp | |
parent | f6c9dec610238bae0d2d61e733d4c29ecf57aa9d (diff) |
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetatype.cpp')
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
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) |