From 0b688e29556bfee806bedb17b89a6ce6689e7979 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 11 Jul 2018 20:38:58 +0200 Subject: [PATCH] Check against copying the husk left by a move The copy-assign operator tests against other.d being NULL but the copy-constructor didn't. This can only matter if the value being copied has been moved from, so we could probably replace with an assertion in practice, but we should at least be consistent. Amended test to check this case too; and verified new test crashes without this fix. Change-Id: I46872a677775944bbdf6a9112e719873e574ae60 Reviewed-by: Thiago Macieira --- src/corelib/tools/qcollator.cpp | 3 ++- tests/auto/corelib/tools/qcollator/tst_qcollator.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index f1e3d6652d..2d17b00ba2 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -89,7 +89,8 @@ QCollator::QCollator(const QLocale &locale) QCollator::QCollator(const QCollator &other) : d(other.d) { - d->ref.ref(); + if (d) + d->ref.ref(); } /*! diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp index 480e723f44..00b22dab6c 100644 --- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp +++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp @@ -72,6 +72,9 @@ void tst_QCollator::moveSemantics() QCOMPARE(c2.locale(), de_AT); QVERIFY(dpointer_is_null(c1)); + QCollator c3(c1); + QVERIFY(dpointer_is_null(c3)); + c1 = std::move(c2); QCOMPARE(c1.locale(), de_AT); QVERIFY(dpointer_is_null(c2));