From 201dc4c43a05098662a31cd338da61b9e47a1e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Thu, 29 Mar 2018 09:46:39 +0100 Subject: [PATCH] coverity#1433645 silence Out-of-bounds read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie098ea6fd2b36e8bc6173f3ca69f2ffc5e312533 Reviewed-on: https://gerrit.libreoffice.org/52062 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sw/source/core/access/accpara.cxx | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index ecc08ddac942..1b98c75b0f81 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -1633,16 +1633,17 @@ uno::Sequence SwAccessibleParagraph::getCharacterAttributes( //sort property values // build sorted index array sal_Int32 nLength = aValues.size(); - std::unique_ptr pIndices( new sal_Int32[nLength] ); - for( i = 0; i < nLength; i++ ) - pIndices[i] = i; - sort( &pIndices[0], &pIndices[nLength], IndexCompare(aValues.data()) ); + std::vector aIndices; + aIndices.reserve(nLength); + for (i = 0; i < nLength; ++i) + aIndices.push_back(i); + std::sort(aIndices.begin(), aIndices.end(), IndexCompare(aValues.data())); // create sorted sequences according to index array uno::Sequence aNewValues( nLength ); PropertyValue* pNewValues = aNewValues.getArray(); - for( i = 0; i < nLength; i++ ) + for (i = 0; i < nLength; ++i) { - pNewValues[i] = aValues[pIndices[i]]; + pNewValues[i] = aValues[aIndices[i]]; } return aNewValues; } @@ -2848,24 +2849,24 @@ sal_Bool SwAccessibleParagraph::setAttributes( // build sorted index array sal_Int32 nLength = rAttributeSet.getLength(); const PropertyValue* pPairs = rAttributeSet.getConstArray(); - sal_Int32* pIndices = new sal_Int32[nLength]; - sal_Int32 i; - for( i = 0; i < nLength; i++ ) - pIndices[i] = i; - sort( &pIndices[0], &pIndices[nLength], IndexCompare(pPairs) ); + std::vector aIndices; + aIndices.reserve(nLength); + for (sal_Int32 i = 0; i < nLength; ++i) + aIndices.push_back(i); + std::sort(aIndices.begin(), aIndices.end(), IndexCompare(pPairs)); // create sorted sequences according to index array uno::Sequence< OUString > aNames( nLength ); OUString* pNames = aNames.getArray(); uno::Sequence< uno::Any > aValues( nLength ); uno::Any* pValues = aValues.getArray(); - for( i = 0; i < nLength; i++ ) + for (sal_Int32 i = 0; i < nLength; ++i) { - const PropertyValue& rVal = pPairs[pIndices[i]]; + const PropertyValue& rVal = pPairs[aIndices[i]]; pNames[i] = rVal.Name; pValues[i] = rVal.Value; } - delete[] pIndices; + aIndices.clear(); // now set the values bool bRet = true;