diff options
author | Noel Grandin <noel@peralex.com> | 2015-11-10 13:36:34 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-11-11 07:16:20 +0000 |
commit | db17d3c17c40d6b0e92392cf3c6e343d1d17b771 (patch) | |
tree | 9d562fcf764e7717df9585ef0e735a12ea4aaa16 /svx | |
parent | 2ce9e4be4a438203382cb9cca824ce3e90647f3a (diff) |
new loplugin: memoryvar
detect when we can convert a new/delete sequence on a local variable to
use std::unique_ptr
Change-Id: Iecae4e4197eccdfacfce2eed39aa4a69e4a660bc
Reviewed-on: https://gerrit.libreoffice.org/19884
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/customshapes/EnhancedCustomShapeFontWork.cxx | 12 | ||||
-rw-r--r-- | svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx | 11 |
2 files changed, 11 insertions, 12 deletions
diff --git a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx index 422952a7766b..9fa46c5fc375 100644 --- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx +++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx @@ -46,6 +46,7 @@ #include <vector> #include <numeric> #include <algorithm> +#include <memory> #include <comphelper/processfactory.hxx> #include <com/sun/star/i18n/BreakIterator.hpp> #include <com/sun/star/i18n/ScriptType.hpp> @@ -268,7 +269,7 @@ void GetTextAreaOutline( const FWData& rFWData, const SdrObject* pCustomShape, F const SvxCharScaleWidthItem& rCharScaleWidthItem = static_cast<const SvxCharScaleWidthItem&>(pCustomShape->GetMergedItem( EE_CHAR_FONTWIDTH )); sal_uInt16 nCharScaleWidth = rCharScaleWidthItem.GetValue(); - long* pDXArry = nullptr; + std::unique_ptr<long[]> pDXArry; sal_Int32 nWidth = 0; // VERTICAL @@ -282,7 +283,7 @@ void GetTextAreaOutline( const FWData& rFWData, const SdrObject* pCustomShape, F { FWCharacterData aCharacterData; OUString aCharText( (sal_Unicode)rText[ i ] ); - if ( pVirDev->GetTextOutlines( aCharacterData.vOutlines, aCharText, 0, 0, -1, true, nWidth, pDXArry ) ) + if ( pVirDev->GetTextOutlines( aCharacterData.vOutlines, aCharText, 0, 0, -1, true, nWidth, pDXArry.get() ) ) { sal_Int32 nTextWidth = pVirDev->GetTextWidth( aCharText); std::vector< tools::PolyPolygon >::iterator aOutlineIter = aCharacterData.vOutlines.begin(); @@ -333,19 +334,18 @@ void GetTextAreaOutline( const FWData& rFWData, const SdrObject* pCustomShape, F { if ( ( nCharScaleWidth != 100 ) && nCharScaleWidth ) { // applying character spacing - pDXArry = new long[ rText.getLength() ]; - pVirDev->GetTextArray( rText, pDXArry); + pDXArry.reset(new long[ rText.getLength() ]); + pVirDev->GetTextArray( rText, pDXArry.get()); FontMetric aFontMetric( pVirDev->GetFontMetric() ); aFont.SetWidth( (sal_Int32)( (double)aFontMetric.GetWidth() * ( (double)100 / (double)nCharScaleWidth ) ) ); pVirDev->SetFont( aFont ); } FWCharacterData aCharacterData; - if ( pVirDev->GetTextOutlines( aCharacterData.vOutlines, rText, 0, 0, -1, true, nWidth, pDXArry ) ) + if ( pVirDev->GetTextOutlines( aCharacterData.vOutlines, rText, 0, 0, -1, true, nWidth, pDXArry.get() ) ) { aParagraphIter->vCharacters.push_back( aCharacterData ); } } - delete[] pDXArry; // vertical alignment std::vector< FWCharacterData >::iterator aCharacterIter( aParagraphIter->vCharacters.begin() ); diff --git a/svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx b/svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx index 9b20d35b4901..161986f2f17a 100644 --- a/svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx +++ b/svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx @@ -20,6 +20,7 @@ #include "svx/EnhancedCustomShapeTypeNames.hxx" #include <osl/mutex.hxx> #include <unordered_map> +#include <memory> typedef std::unordered_map< const char*, MSO_SPT, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap; @@ -288,12 +289,11 @@ MSO_SPT EnhancedCustomShapeTypeNames::Get( const OUString& rShapeType ) } MSO_SPT eRetValue = mso_sptNil; int i, nLen = rShapeType.getLength(); - char* pBuf = new char[ nLen + 1 ]; + std::unique_ptr<char[]> pBuf(new char[ nLen + 1 ]); for ( i = 0; i < nLen; i++ ) pBuf[ i ] = (char)rShapeType[ i ]; pBuf[ i ] = 0; - TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) ); - delete[] pBuf; + TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf.get() ) ); if ( aHashIter != pHashMap->end() ) eRetValue = (*aHashIter).second; return eRetValue; @@ -544,12 +544,11 @@ OUString EnhancedCustomShapeTypeNames::GetAccName( const OUString& rShapeType ) } OUString sRetValue; int i, nLen = rShapeType.getLength(); - char* pBuf = new char[ nLen + 1 ]; + std::unique_ptr<char[]> pBuf(new char[ nLen + 1 ]); for ( i = 0; i < nLen; i++ ) pBuf[ i ] = (char)rShapeType[ i ]; pBuf[ i ] = 0; - TypeACCNameHashMap::iterator aHashIter( pACCHashMap->find( pBuf ) ); - delete[] pBuf; + TypeACCNameHashMap::iterator aHashIter( pACCHashMap->find( pBuf.get() ) ); if ( aHashIter != pACCHashMap->end() ) sRetValue = OUString::createFromAscii( (*aHashIter).second ); return sRetValue; |