summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qcollator_macx.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/corelib/text/qcollator_macx.cpp b/src/corelib/text/qcollator_macx.cpp
index 62b3a904a05..713df755007 100644
--- a/src/corelib/text/qcollator_macx.cpp
+++ b/src/corelib/text/qcollator_macx.cpp
@@ -126,17 +126,19 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const
return QCollatorSortKey(nullptr);
}
- //Documentation recommends having it 5 times as big as the input
+ auto text = reinterpret_cast<const UniChar *>(string.constData());
+ // Documentation recommends having it 5 times as big as the input
QList<UCCollationValue> ret(string.size() * 5);
ItemCount actualSize;
- int status = UCGetCollationKey(d->collator,
- reinterpret_cast<const UniChar *>(string.constData()),
- string.count(), ret.size(), &actualSize, ret.data());
+ int status = UCGetCollationKey(d->collator, text, string.count(),
+ ret.size(), &actualSize, ret.data());
ret.resize(actualSize + 1);
if (status == kUCOutputBufferTooSmall) {
- UCGetCollationKey(d->collator, reinterpret_cast<const UniChar *>(string.constData()),
- string.count(), ret.size(), &actualSize, ret.data());
+ status = UCGetCollationKey(d->collator, text, string.count(),
+ ret.size(), &actualSize, ret.data());
+ Q_ASSERT(status != kUCOutputBufferTooSmall);
+ Q_ASSERT(ret.size() == actualSize + 1);
}
ret[actualSize] = 0;
return QCollatorSortKey(new QCollatorSortKeyPrivate(std::move(ret)));
@@ -150,7 +152,7 @@ int QCollatorSortKey::compare(const QCollatorSortKey &key) const
SInt32 order;
UCCompareCollationKeys(d->m_key.data(), d->m_key.size(),
key.d->m_key.data(), key.d->m_key.size(),
- 0, &order);
+ nullptr, &order);
return order;
}