From 009f1f28120c473632d4a91d6a79c056ac2bbe6a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 5 Aug 2016 16:01:39 +0300 Subject: 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 --- src/corelib/tools/qstring.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 87b222881c..7c4280d36b 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -5402,7 +5402,7 @@ int QString::compare_helper(const QChar *data1, int length1, const char *data2, Qt::CaseSensitivity cs) { if (!data2) - return int(bool(data1)); + return length1; if (Q_UNLIKELY(length2 < 0)) length2 = int(strlen(data2)); // ### make me nothrow in all cases -- cgit v1.2.3