From c0f7ecab2084e3e720a012d1254f52bfbbe1446e Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 6 Jun 2020 01:28:12 +0200 Subject: [PATCH] QVariant: remove UB and fix semantics in a test The code was reading from uninitialized memory when creating a variant. Fixing that reveals that the test semantics are broken: when dealing with datatypes without a registered operator==, QVariant resorts to memcmp, so the two objects would've actually compared equal. Amend that. Change-Id: I36bad7ee6a45154d5d534b7dd8b618cc0a900126 Reviewed-by: Volker Hilsheimer --- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index c1c475b9c6..69322356a8 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -2865,15 +2865,15 @@ void tst_QVariant::compareCustomTypes() const { qRegisterMetaType("WontCompare"); - WontCompare f1; + WontCompare f1 = {}; f1.x = 0; const QVariant variant1(QVariant::fromValue(f1)); - WontCompare f2; - f2.x = 0; + WontCompare f2 = {}; + f2.x = 1; const QVariant variant2(QVariant::fromValue(f2)); - /* We compare pointers. */ + /* We compare via memcmp. */ QVERIFY(variant1 != variant2); QCOMPARE(variant1, variant1); QCOMPARE(variant2, variant2);