diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-08-05 16:01:39 +0300 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-05 18:52:16 +0000 |
commit | 009f1f28120c473632d4a91d6a79c056ac2bbe6a (patch) | |
tree | 5dd48607dbe1e95367debfe7613c94b21acf4360 /tests | |
parent | 4b63ab9a93dfcdad5bdcce3aa437e16598233ca1 (diff) |
QString: fix regression comparing null QString with null const char *
Commit 4a40c717f3cf1ae181df49c91261a12d5e33e5a4 optimized
QString::compare_helper(QChar*, int, char*, int), but got
the case wrong where the rhs is null, but the lhs is empty,
not null (which is the case even with a null QString, as
QString().constData() != nullptr). The correct result in
this case is 0, since in Qt empty and null strings compare
equal.
Fix by checking the length of lhs, not its pointer.
Task-number: QTBUG-55154
Change-Id: I3ec2cd25d9bdca90cf3f5568a875b1e52c779979
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 6df9ad7cdf..36784435b8 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -5012,6 +5012,12 @@ void tst_QString::operator_eqeq_nullstring() QVERIFY( QString("") == "" ); QVERIFY( "" == QString("") ); + QVERIFY(QString() == nullptr); + QVERIFY(nullptr == QString()); + + QVERIFY(QString("") == nullptr); + QVERIFY(nullptr == QString("")); + QVERIFY( QString().size() == 0 ); QVERIFY( QString("").size() == 0 ); @@ -5025,6 +5031,8 @@ void tst_QString::operator_smaller() QString null; QString empty(""); QString foo("foo"); + const char *nullC = nullptr; + const char *emptyC = ""; QVERIFY( !(null < QString()) ); QVERIFY( !(null > QString()) ); @@ -5035,6 +5043,12 @@ void tst_QString::operator_smaller() QVERIFY( !(null < empty) ); QVERIFY( !(null > empty) ); + QVERIFY( !(nullC < empty) ); + QVERIFY( !(nullC > empty) ); + + QVERIFY( !(null < emptyC) ); + QVERIFY( !(null > emptyC) ); + QVERIFY( null < foo ); QVERIFY( !(null > foo) ); QVERIFY( foo > null ); |