Fix assertion on passing nullptr QLatin1Strings to qt_compare_strings

qstrnicmp() has an assertion that the lhs string is not nullptr.

Fix by moving the length check back to the front, regardless of cs's
value.

Amends cad7100fda1b27ba56c4d9efc6bceba62859dfbc.

Change-Id: I31f808936c8dc6fbb10a70a59923746ef3e675e9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2019-08-24 06:47:41 +02:00
parent 09bfc52dde
commit b3dc0c13e8

View File

@ -1199,10 +1199,10 @@ static int qt_compare_strings(QLatin1String lhs, QStringView rhs, Qt::CaseSensit
static int qt_compare_strings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
{
if (cs == Qt::CaseInsensitive)
return qstrnicmp(lhs.data(), lhs.size(), rhs.data(), rhs.size());
if (lhs.isEmpty())
return lencmp(0, rhs.size());
if (cs == Qt::CaseInsensitive)
return qstrnicmp(lhs.data(), lhs.size(), rhs.data(), rhs.size());
const auto l = std::min(lhs.size(), rhs.size());
int r = qstrncmp(lhs.data(), rhs.data(), l);
return r ? r : lencmp(lhs.size(), rhs.size());