diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-04-06 09:46:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-04-06 09:22:46 +0000 |
commit | aa09b0c27a6d925da428d6267daadc7338829869 (patch) | |
tree | b0fa576ff64820061d9fb876bebacd23e58ddc56 /sw | |
parent | 0c82dff153d92150729815b919854a9a350aa031 (diff) |
loplugin:useuniqueptr extend to catch more localvar cases
i.e. where the code looks like
{
foo * p = new foo;
...
delete p;
return ...;
}
Change-Id: Id5f2e55d0363fc62c72535a23faeaaf1f0ac6aee
Reviewed-on: https://gerrit.libreoffice.org/36190
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/access/accpara.cxx | 3 | ||||
-rw-r--r-- | sw/source/core/doc/doccomp.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/docnode/ndtbl.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/txtnode/fntcache.cxx | 53 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexportfilter.cxx | 7 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.cxx | 9 |
6 files changed, 34 insertions, 47 deletions
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index 4af5ec7beeee..5ec175e4fb9a 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -1674,7 +1674,7 @@ uno::Sequence<PropertyValue> SwAccessibleParagraph::getCharacterAttributes( //sort property values // build sorted index array sal_Int32 nLength = aValues.size(); - sal_Int32* pIndices = new sal_Int32[nLength]; + std::unique_ptr<sal_Int32[]> pIndices( new sal_Int32[nLength] ); for( i = 0; i < nLength; i++ ) pIndices[i] = i; sort( &pIndices[0], &pIndices[nLength], IndexCompare(aValues.data()) ); @@ -1685,7 +1685,6 @@ uno::Sequence<PropertyValue> SwAccessibleParagraph::getCharacterAttributes( { pNewValues[i] = aValues[pIndices[i]]; } - delete[] pIndices; return aNewValues; } diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx index 707d5c1a05bf..78d3fafd74a6 100644 --- a/sw/source/core/doc/doccomp.cxx +++ b/sw/source/core/doc/doccomp.cxx @@ -2337,7 +2337,7 @@ int CommonSubseq::FindLCS( int *pLcs1, int *pLcs2, int nStt1, int nEnd1, OSL_ASSERT( nLen1 >= 0 ); OSL_ASSERT( nLen2 >= 0 ); - int **pLcs = new int*[ nLen1 + 1 ]; + std::unique_ptr<int*[]> pLcs( new int*[ nLen1 + 1 ] ); pLcs[ 0 ] = pData.get(); for( int i = 1; i < nLen1 + 1; i++ ) @@ -2387,8 +2387,6 @@ int CommonSubseq::FindLCS( int *pLcs1, int *pLcs2, int nStt1, int nEnd1, } } - delete[] pLcs; - return nLcsLen; } diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index e81e481cacba..7fb80ffbb457 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -3920,8 +3920,8 @@ OUString SwDoc::GetUniqueTableName() const const size_t nFlagSize = ( mpTableFrameFormatTable->size() / 8 ) + 2; - sal_uInt8* pSetFlags = new sal_uInt8[ nFlagSize ]; - memset( pSetFlags, 0, nFlagSize ); + std::unique_ptr<sal_uInt8[]> pSetFlags( new sal_uInt8[ nFlagSize ] ); + memset( pSetFlags.get(), 0, nFlagSize ); for( size_t n = 0; n < mpTableFrameFormatTable->size(); ++n ) { @@ -3955,7 +3955,6 @@ OUString SwDoc::GetUniqueTableName() const } } - delete [] pSetFlags; return aName + OUString::number( ++nNum ); } diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx index 85bf990db61c..77dc717bda0c 100644 --- a/sw/source/core/txtnode/fntcache.cxx +++ b/sw/source/core/txtnode/fntcache.cxx @@ -928,13 +928,13 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc); // kerning array - gives the absolute position of end of each character - long* pKernArray = new long[rInf.GetLen()]; + std::unique_ptr<long[]> pKernArray(new long[rInf.GetLen()]); if ( m_pPrinter ) - m_pPrinter->GetTextArray( rInf.GetText(), pKernArray, + m_pPrinter->GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); else - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); // Change the average width per character to an appropriate grid width @@ -1017,9 +1017,8 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) rInf.GetFrame()->SwitchHorizontalToVertical( aTextOriginPos ); rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), rInf.GetLen() ); + pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); - delete[] pKernArray; return; } } @@ -1037,13 +1036,13 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) { const long nGridWidthAdd = EvalGridWidthAdd( pGrid, rInf ); - long* pKernArray = new long[rInf.GetLen()]; + std::unique_ptr<long[]> pKernArray( new long[rInf.GetLen()] ); if ( m_pPrinter ) - m_pPrinter->GetTextArray( rInf.GetText(), pKernArray, + m_pPrinter->GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); else - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); if ( bSwitchH2V ) rInf.GetFrame()->SwitchHorizontalToVertical( aTextOriginPos ); @@ -1060,7 +1059,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) pSI && pSI->CountCompChg() && lcl_IsMonoSpaceFont( *(rInf.GetpOut()) ) ) { - pSI->Compress( pKernArray, rInf.GetIdx(), rInf.GetLen(), + pSI->Compress( pKernArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), (sal_uInt16)m_aFont.GetFontSize().Height(), lcl_IsFullstopCentered( rInf.GetOut() ) , &aTextOriginPos ); bSpecialJust = true; } @@ -1105,19 +1104,19 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) { pKernArray[0] = rInf.GetWidth() + nSpaceAdd; rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), 1 ); + pKernArray.get(), rInf.GetIdx(), 1 ); } else { pKernArray[ rInf.GetLen() - 2] += nSpaceAdd; rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), rInf.GetLen() ); + pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); } } else { rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), rInf.GetLen() ); + pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); } } else @@ -1155,9 +1154,8 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) pKernArray[i] += nGridAddSum; } rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), rInf.GetLen() ); + pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); } - delete[] pKernArray; return; } } @@ -2004,18 +2002,18 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf ) if( 0 != nSperren ) nKern -= nSperren; - long* pKernArray = new long[ rInf.GetLen() ]; + std::unique_ptr<long[]> pKernArray( new long[ rInf.GetLen() ] ); // be sure to have the correct layout mode at the printer if ( m_pPrinter ) { m_pPrinter->SetLayoutMode( rInf.GetOut().GetLayoutMode() ); m_pPrinter->SetDigitLanguage( rInf.GetOut().GetDigitLanguage() ); - m_pPrinter->GetTextArray( rInf.GetText(), pKernArray, + m_pPrinter->GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); } else - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); const SwScriptInfo* pSI = rInf.GetScriptInfo(); @@ -2028,7 +2026,7 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf ) pSI && pSI->CountCompChg() && lcl_IsMonoSpaceFont( rInf.GetOut() ) ) { - pSI->Compress( pKernArray, rInf.GetIdx(), rInf.GetLen(), + pSI->Compress( pKernArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), (sal_uInt16) m_aFont.GetFontSize().Height(), lcl_IsFullstopCentered( rInf.GetOut() ) ); @@ -2041,7 +2039,7 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf ) if (!MsLangId::isKorean(aLang)) { - SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray, nullptr, + SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray.get(), nullptr, rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd ); nSpaceAdd = 0; @@ -2055,7 +2053,7 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf ) if ( SwScriptInfo::IsArabicText( rInf.GetText(), rInf.GetIdx(), rInf.GetLen() ) ) { if ( pSI && pSI->CountKashida() && - pSI->KashidaJustify( pKernArray, nullptr, rInf.GetIdx(), rInf.GetLen(), + pSI->KashidaJustify( pKernArray.get(), nullptr, rInf.GetIdx(), rInf.GetLen(), nSpaceAdd ) != -1 ) nSpaceAdd = 0; } @@ -2068,7 +2066,7 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf ) if ( LANGUAGE_THAI == aLang ) { - SwScriptInfo::ThaiJustify( rInf.GetText(), pKernArray, nullptr, + SwScriptInfo::ThaiJustify( rInf.GetText(), pKernArray.get(), nullptr, rInf.GetIdx(), rInf.GetLen(), rInf.GetNumberOfBlanks(), rInf.GetSpace() ); @@ -2106,7 +2104,6 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf ) if ( 2 * ( rInf.GetOfst() - nCnt * nAvgWidthPerChar ) > nAvgWidthPerChar ) ++nCnt; - delete[] pKernArray; return nCnt; } } @@ -2130,7 +2127,6 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf ) break; } } - delete[] pKernArray; return nCnt; } } @@ -2188,7 +2184,6 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf ) if ( pSI ) rInf.SetCursorBidiLevel( pSI->DirType( nLastIdx ) ); - delete[] pKernArray; return nCnt; } @@ -2330,8 +2325,8 @@ sal_Int32 SwFont::GetTextBreak( SwDrawTextInfo& rInf, long nTextWidth ) const SwDoc* pDoc = rInf.GetShell()->GetDoc(); const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc); - long* pKernArray = new long[rInf.GetLen()]; - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + std::unique_ptr<long[]> pKernArray( new long[rInf.GetLen()] ); + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); long nAvgWidthPerChar = pKernArray[ rInf.GetLen() - 1 ] / rInf.GetLen(); @@ -2349,7 +2344,6 @@ sal_Int32 SwFont::GetTextBreak( SwDrawTextInfo& rInf, long nTextWidth ) ++nTextBreak; } - delete[] pKernArray; return nTextBreak + rInf.GetIdx(); } } @@ -2363,8 +2357,8 @@ sal_Int32 SwFont::GetTextBreak( SwDrawTextInfo& rInf, long nTextWidth ) { const long nGridWidthAdd = EvalGridWidthAdd( pGrid, rInf ); - long* pKernArray = new long[rInf.GetLen()]; - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + std::unique_ptr<long[]> pKernArray( new long[rInf.GetLen()] ); + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); long nCurrPos = pKernArray[nTextBreak] + nGridWidthAdd; while( nTextBreak < rInf.GetLen() && nTextWidth >= nCurrPos) @@ -2372,7 +2366,6 @@ sal_Int32 SwFont::GetTextBreak( SwDrawTextInfo& rInf, long nTextWidth ) nTextBreak++; nCurrPos = pKernArray[nTextBreak] + nGridWidthAdd * ( nTextBreak + 1 ); } - delete[] pKernArray; return nTextBreak + rInf.GetIdx(); } } diff --git a/sw/source/filter/ww8/docxexportfilter.cxx b/sw/source/filter/ww8/docxexportfilter.cxx index fe6b8abdff29..c3859af0844a 100644 --- a/sw/source/filter/ww8/docxexportfilter.cxx +++ b/sw/source/filter/ww8/docxexportfilter.cxx @@ -62,21 +62,20 @@ bool DocxExportFilter::exportDocument() aPam.SetMark(); aPam.Move( fnMoveBackward, GoInDoc ); - SwPaM *pCurPam = new SwPaM( *aPam.End(), *aPam.Start() ); + std::unique_ptr<SwPaM> pCurPam( new SwPaM( *aPam.End(), *aPam.Start() ) ); // export the document // (in a separate block so that it's destructed before the commit) { - DocxExport aExport( this, pDoc, pCurPam, &aPam ); + DocxExport aExport( this, pDoc, pCurPam.get(), &aPam ); aExport.ExportDocument( true ); // FIXME support exporting selection only } commitStorage(); // delete the pCurPam - while ( pCurPam->GetNext() != pCurPam ) + while ( pCurPam->GetNext() != pCurPam.get() ) delete pCurPam->GetNext(); - delete pCurPam; return true; } diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index dab0c4e5474d..beb35144f743 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -220,10 +220,10 @@ OUString SwWW8ImplReader::ReadRawUniString(SvMemoryStream& rStrm, sal_uInt16 nCh sal_Unicode mcNulSubst = '\0'; sal_uInt16 nCharsLeft = nChars; - sal_Unicode* pcBuffer = new sal_Unicode[ nCharsLeft + 1 ]; + std::unique_ptr<sal_Unicode[]> pcBuffer( new sal_Unicode[ nCharsLeft + 1 ] ); - sal_Unicode* pcUniChar = pcBuffer; - sal_Unicode* pcEndChar = pcBuffer + nCharsLeft; + sal_Unicode* pcUniChar = pcBuffer.get(); + sal_Unicode* pcEndChar = pcBuffer.get() + nCharsLeft; if( b16Bit ) { @@ -245,8 +245,7 @@ OUString SwWW8ImplReader::ReadRawUniString(SvMemoryStream& rStrm, sal_uInt16 nCh } *pcEndChar = '\0'; - OUString aRet(pcBuffer); - delete[] pcBuffer; + OUString aRet(pcBuffer.get()); return aRet; } |