tst_QMetaType: fix UB (nullptr passed to memcmp()) in selfCompare()

QMetaType::Void is not constructible, so create() will return nullptr,
and even though sizeOf() returns 0, calling memcmp() is still UB in
that case.

Fix by guarding the memcmp() from QMetaType::Void.

Amends a59e7361714d50687d82a2d9abae9e95825a23b6.

Pick-to: 6.9 6.8 6.5
Change-Id: I55896826e6c0cad5d77e9d0ab861efa9a32f780f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2025-04-01 15:35:34 +02:00
parent 0475bc57d6
commit c6c2a0bf37

View File

@ -1683,6 +1683,7 @@ void tst_QMetaType::selfCompare()
case QMetaType::MetaTypeName:
FOR_EACH_PRIMITIVE_METATYPE(ADD_METATYPE_CASE)
#undef ADD_METATYPE_CASE
if (type != QMetaType::Void)
QCOMPARE(memcmp(v1, v2, t.sizeOf()), 0);
}
}