summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-01-27 13:12:45 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2020-02-05 10:23:43 +0100
commit41b2c477b771e7c214d09138af1a48701f573912 (patch)
tree40859456598150a6970bb9fd7441db2009286465 /src
parent056230cc9c3309823a93df0e34c92affb29df9e4 (diff)
Take care of NULL data from QStringView in QCollator
Back-ends need to catch NULL data so as not to call system APIs with invalid pointers. [ChangeLog][QtCore][QCollator] Fixed a regression introduced in 5.14.0 that caused QCollator not to operate with default-constructed QStrings and print a warning on Windows. Fixes: QTBUG-81673 Change-Id: I2eafe1e188b436afcca3cf2ecdf98bba707c44c9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qcollator_icu.cpp7
-rw-r--r--src/corelib/text/qcollator_macx.cpp7
-rw-r--r--src/corelib/text/qcollator_posix.cpp7
-rw-r--r--src/corelib/text/qcollator_win.cpp7
4 files changed, 24 insertions, 4 deletions
diff --git a/src/corelib/text/qcollator_icu.cpp b/src/corelib/text/qcollator_icu.cpp
index 8acda45070..0dca1ee9c9 100644
--- a/src/corelib/text/qcollator_icu.cpp
+++ b/src/corelib/text/qcollator_icu.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
** Contact: https://www.qt.io/licensing/
**
@@ -109,6 +109,11 @@ void QCollatorPrivate::cleanup()
int QCollator::compare(QStringView s1, QStringView s2) const
{
+ if (!s1.size())
+ return s2.size() ? -1 : 0;
+ if (!s2.size())
+ return +1;
+
if (d->dirty)
d->init();
diff --git a/src/corelib/text/qcollator_macx.cpp b/src/corelib/text/qcollator_macx.cpp
index 071d7c048f..cb8e073d4a 100644
--- a/src/corelib/text/qcollator_macx.cpp
+++ b/src/corelib/text/qcollator_macx.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
+** Copyright (C) 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -94,6 +94,11 @@ void QCollatorPrivate::cleanup()
int QCollator::compare(QStringView s1, QStringView s2) const
{
+ if (!s1.size())
+ return s2.size() ? -1 : 0;
+ if (!s2.size())
+ return +1;
+
if (d->dirty)
d->init();
if (!d->collator)
diff --git a/src/corelib/text/qcollator_posix.cpp b/src/corelib/text/qcollator_posix.cpp
index 9cbc539ebe..ffcd214cfb 100644
--- a/src/corelib/text/qcollator_posix.cpp
+++ b/src/corelib/text/qcollator_posix.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
+** Copyright (C) 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -75,6 +75,11 @@ static void stringToWCharArray(QVarLengthArray<wchar_t> &ret, QStringView string
int QCollator::compare(QStringView s1, QStringView s2) const
{
+ if (!s1.size())
+ return s2.size() ? -1 : 0;
+ if (!s2.size())
+ return +1;
+
if (d->isC())
return s1.compare(s2, caseSensitivity());
if (d->dirty)
diff --git a/src/corelib/text/qcollator_win.cpp b/src/corelib/text/qcollator_win.cpp
index 9d81de882f..54f57f1d24 100644
--- a/src/corelib/text/qcollator_win.cpp
+++ b/src/corelib/text/qcollator_win.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
+** Copyright (C) 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -89,6 +89,11 @@ void QCollatorPrivate::cleanup()
int QCollator::compare(QStringView s1, QStringView s2) const
{
+ if (!s1.size())
+ return s2.size() ? -1 : 0;
+ if (!s2.size())
+ return +1;
+
if (d->isC())
return s1.compare(s2, d->caseSensitivity);