QString: fix comparisons to null strings in ucstricmp
Commit 8f52ad9fe0
("ucstricmp: compare
null and empty strings equal") made sure empties and nulls would compare
equally, but may have broken the null vs non-empty comparison (which was
not tested). The commit message also said that it expected all callers
to handle null before calling into those functions, but that's not the
case for QStringView created from a null QString: the incoming "a"
pointer was null.
So just remove the checks for null pointers and rely on the size checks
doing the right thing.
[ChangeLog][QtCore][QString] Fixed a regression from 5.9 that caused
comparing default-constructed QStrings to be sorted after non-empty
strings.
Task-number: QTBUG-65939
Change-Id: I56b444f9d6274221a3b7fffd150c83ad46c599b6
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
15ae794966
commit
ea6675374f
@ -423,10 +423,6 @@ static int ucstricmp(const QChar *a, const QChar *ae, const QChar *b, const QCha
|
||||
{
|
||||
if (a == b)
|
||||
return (ae - be);
|
||||
if (a == 0)
|
||||
return be - b;
|
||||
if (b == 0)
|
||||
return a - ae;
|
||||
|
||||
const QChar *e = ae;
|
||||
if (be - b < ae - a)
|
||||
@ -455,11 +451,6 @@ static int ucstricmp(const QChar *a, const QChar *ae, const QChar *b, const QCha
|
||||
// Case-insensitive comparison between a Unicode string and a QLatin1String
|
||||
static int ucstricmp(const QChar *a, const QChar *ae, const char *b, const char *be)
|
||||
{
|
||||
if (!a)
|
||||
return be - b;
|
||||
if (!b)
|
||||
return a - ae;
|
||||
|
||||
auto e = ae;
|
||||
if (be - b < ae - a)
|
||||
e = a + (be - b);
|
||||
|
@ -6043,8 +6043,14 @@ void tst_QString::compare_data()
|
||||
QTest::addColumn<int>("csr"); // case sensitive result
|
||||
QTest::addColumn<int>("cir"); // case insensitive result
|
||||
|
||||
|
||||
// null strings
|
||||
QTest::newRow("null-null") << QString() << QString() << 0 << 0;
|
||||
QTest::newRow("text-null") << QString("a") << QString() << 1 << 1;
|
||||
QTest::newRow("null-text") << QString() << QString("a") << -1 << -1;
|
||||
QTest::newRow("null-empty") << QString() << QString("") << 0 << 0;
|
||||
QTest::newRow("empty-null") << QString("") << QString() << 0 << 0;
|
||||
|
||||
// empty strings
|
||||
QTest::newRow("data0") << QString("") << QString("") << 0 << 0;
|
||||
QTest::newRow("data1") << QString("a") << QString("") << 1 << 1;
|
||||
QTest::newRow("data2") << QString("") << QString("a") << -1 << -1;
|
||||
|
Loading…
Reference in New Issue
Block a user