tdf#163486: PVS: Array overrun is possible

Change-Id: Ib4b0984d828927b67200acd24ce4a22f4b0e57e5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175677
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Julien Nabet 2024-10-26 12:21:54 +02:00 committed by Mike Kaganski
parent 0545d627c6
commit 1a1d67396c

View file

@ -1004,15 +1004,15 @@ Document::retrieveCharacterAttributes(
// sort the attributes
auto nLength = static_cast<size_t>(aRes.getLength());
std::unique_ptr<sal_Int32[]> pIndices( new sal_Int32[nLength] );
std::iota(&pIndices[0], &pIndices[nLength], 0);
std::sort(&pIndices[0], &pIndices[nLength],
std::vector<sal_Int32> pIndices(nLength);
std::iota(pIndices.begin(), pIndices.end(), 0);
std::sort(pIndices.begin(), pIndices.end(),
[&aRes](sal_Int32 a, sal_Int32 b) { return aRes[a].Name < aRes[b].Name; });
// create sorted sequences according to index array
std::vector<css::beans::PropertyValue> aNewValues;
aNewValues.reserve(nLength);
std::transform(&pIndices[0], &pIndices[nLength], std::back_inserter(aNewValues),
std::transform(pIndices.begin(), pIndices.end(), std::back_inserter(aNewValues),
[&aRes](const sal_Int32 nIdx) -> const css::beans::PropertyValue& { return aRes[nIdx]; });
return comphelper::containerToSequence(aNewValues);