From 414ca19a3f040bd579906899558e1486286335a1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 1 Apr 2025 15:35:34 +0200 Subject: [PATCH] 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.8 6.5 Change-Id: I55896826e6c0cad5d77e9d0ab861efa9a32f780f Reviewed-by: Fabian Kosmale Reviewed-by: Thiago Macieira (cherry picked from commit c6c2a0bf3799c9851551bc9e1bd0919dbc64924c) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index e7c45ac3dae..ac3dfb06dd8 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1705,7 +1705,8 @@ void tst_QMetaType::selfCompare() case QMetaType::MetaTypeName: FOR_EACH_PRIMITIVE_METATYPE(ADD_METATYPE_CASE) #undef ADD_METATYPE_CASE - QCOMPARE(memcmp(v1, v2, t.sizeOf()), 0); + if (type != QMetaType::Void) + QCOMPARE(memcmp(v1, v2, t.sizeOf()), 0); } }