Use the correct size argument for wcsxfrm
The documentation says that the size argument to wcsxfrm should include the null terminating character. Currently it doesn't, which breaks collation, as the last character is omitted. Task-number: QTBUG-109954 Change-Id: Ic0c78a617ed1d50e31e50cae56e21675d2069ead Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
696ad54e5d
commit
80686be086
@ -69,13 +69,19 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const
|
|||||||
if (d->isC()) {
|
if (d->isC()) {
|
||||||
std::copy(original.cbegin(), original.cend(), result.begin());
|
std::copy(original.cbegin(), original.cend(), result.begin());
|
||||||
} else {
|
} else {
|
||||||
size_t size = std::wcsxfrm(result.data(), original.constData(), string.size());
|
auto availableSizeIncludingNullTerminator = result.size();
|
||||||
if (size > size_t(result.size())) {
|
size_t neededSizeExcludingNullTerminator = std::wcsxfrm(
|
||||||
result.resize(size+1);
|
result.data(), original.constData(), availableSizeIncludingNullTerminator);
|
||||||
size = std::wcsxfrm(result.data(), original.constData(), string.size());
|
if (neededSizeExcludingNullTerminator > size_t(availableSizeIncludingNullTerminator - 1)) {
|
||||||
|
result.resize(neededSizeExcludingNullTerminator + 1);
|
||||||
|
availableSizeIncludingNullTerminator = result.size();
|
||||||
|
neededSizeExcludingNullTerminator = std::wcsxfrm(result.data(), original.constData(),
|
||||||
|
availableSizeIncludingNullTerminator);
|
||||||
|
Q_ASSERT(neededSizeExcludingNullTerminator
|
||||||
|
== size_t(availableSizeIncludingNullTerminator - 1));
|
||||||
}
|
}
|
||||||
result.resize(size+1);
|
result.resize(neededSizeExcludingNullTerminator + 1);
|
||||||
result[size] = 0;
|
result[neededSizeExcludingNullTerminator] = 0;
|
||||||
}
|
}
|
||||||
return QCollatorSortKey(new QCollatorSortKeyPrivate(std::move(result)));
|
return QCollatorSortKey(new QCollatorSortKeyPrivate(std::move(result)));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user