Fix warnings about uninitialized variables
qtbase/src/corelib/kernel/qmetatype.cpp: In static member function ‘static void QMetaType::destroy(int, void*)’: qtbase/src/corelib/kernel/qmetatype.cpp:2599:27: error: ‘info.QMetaType::m_destructor’ may be used uninitialized in this function [-Werror=maybe-uninitialized] if (m_typedDestructor && !m_destructor) ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ qtbase/src/corelib/kernel/qmetatype.cpp:1868:15: note: ‘info.QMetaType::m_destructor’ was declared here QMetaType info(type); ^~~~ qtbase/src/corelib/kernel/qmetatype.cpp:2600:26: error: ‘info.QMetaType::m_typedDestructor’ may be used uninitialized in this function [-Werror=maybe-uninitialized] m_typedDestructor(m_typeId, data); ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ qtbase/src/corelib/kernel/qmetatype.cpp:1868:15: note: ‘info.QMetaType::m_typedDestructor’ was declared here QMetaType info(type); ^~~~ The extended (not inlined) function may be called on a half initialized invalid instance. Change-Id: I26d677a8ad2bd0c5846233f06393e774d377936d Reviewed-by: Liang Qi <liang.qi@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
45e4dfb449
commit
ecdccce8e4
@ -2566,6 +2566,8 @@ void *QMetaType::createExtended(const void *copy) const
|
|||||||
*/
|
*/
|
||||||
void QMetaType::destroyExtended(void *data) const
|
void QMetaType::destroyExtended(void *data) const
|
||||||
{
|
{
|
||||||
|
if (m_typeId == QMetaType::UnknownType)
|
||||||
|
return;
|
||||||
if (Q_UNLIKELY(m_typedDestructor && !m_destructor))
|
if (Q_UNLIKELY(m_typedDestructor && !m_destructor))
|
||||||
m_typedDestructor(m_typeId, data);
|
m_typedDestructor(m_typeId, data);
|
||||||
else
|
else
|
||||||
@ -2582,6 +2584,8 @@ void QMetaType::destroyExtended(void *data) const
|
|||||||
*/
|
*/
|
||||||
void *QMetaType::constructExtended(void *where, const void *copy) const
|
void *QMetaType::constructExtended(void *where, const void *copy) const
|
||||||
{
|
{
|
||||||
|
if (m_typeId == QMetaType::UnknownType)
|
||||||
|
return nullptr;
|
||||||
if (m_typedConstructor && !m_constructor)
|
if (m_typedConstructor && !m_constructor)
|
||||||
return m_typedConstructor(m_typeId, where, copy);
|
return m_typedConstructor(m_typeId, where, copy);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -2596,6 +2600,8 @@ void *QMetaType::constructExtended(void *where, const void *copy) const
|
|||||||
*/
|
*/
|
||||||
void QMetaType::destructExtended(void *data) const
|
void QMetaType::destructExtended(void *data) const
|
||||||
{
|
{
|
||||||
|
if (m_typeId == QMetaType::UnknownType)
|
||||||
|
return;
|
||||||
if (m_typedDestructor && !m_destructor)
|
if (m_typedDestructor && !m_destructor)
|
||||||
m_typedDestructor(m_typeId, data);
|
m_typedDestructor(m_typeId, data);
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,7 @@ private slots:
|
|||||||
void compareCustomType();
|
void compareCustomType();
|
||||||
void compareCustomEqualOnlyType();
|
void compareCustomEqualOnlyType();
|
||||||
void customDebugStream();
|
void customDebugStream();
|
||||||
|
void unknownType();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BaseGenericType
|
struct BaseGenericType
|
||||||
@ -2529,6 +2530,16 @@ void tst_QMetaType::customDebugStream()
|
|||||||
qDebug() << v1;
|
qDebug() << v1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QMetaType::unknownType()
|
||||||
|
{
|
||||||
|
QMetaType invalid(QMetaType::UnknownType);
|
||||||
|
QVERIFY(!invalid.create());
|
||||||
|
QVERIFY(!invalid.sizeOf());
|
||||||
|
QVERIFY(!invalid.metaObject());
|
||||||
|
int buffer = 0xBAD;
|
||||||
|
invalid.construct(&buffer);
|
||||||
|
QCOMPARE(buffer, 0xBAD);
|
||||||
|
}
|
||||||
// Compile-time test, it should be possible to register function pointer types
|
// Compile-time test, it should be possible to register function pointer types
|
||||||
class Undefined;
|
class Undefined;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user