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 | |
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>
21 files changed, 103 insertions, 146 deletions
diff --git a/accessibility/source/extended/textwindowaccessibility.cxx b/accessibility/source/extended/textwindowaccessibility.cxx index 754526db7b75..741712b40c4b 100644 --- a/accessibility/source/extended/textwindowaccessibility.cxx +++ b/accessibility/source/extended/textwindowaccessibility.cxx @@ -1043,7 +1043,7 @@ Document::retrieveCharacterAttributes( // sort the attributes sal_Int32 nLength = aRes.getLength(); const css::beans::PropertyValue* pPairs = aRes.getConstArray(); - 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; std::sort( &pIndices[0], &pIndices[nLength], IndexCompare(pPairs) ); @@ -1054,7 +1054,6 @@ Document::retrieveCharacterAttributes( { pNewValues[i] = pPairs[pIndices[i]]; } - delete[] pIndices; return aNewValues; } diff --git a/basegfx/source/matrix/b2dhommatrix.cxx b/basegfx/source/matrix/b2dhommatrix.cxx index 2dce96fb2379..7e228ca48dea 100644 --- a/basegfx/source/matrix/b2dhommatrix.cxx +++ b/basegfx/source/matrix/b2dhommatrix.cxx @@ -24,6 +24,7 @@ #include <basegfx/tuple/b2dtuple.hxx> #include <basegfx/vector/b2dvector.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> +#include <memory> namespace basegfx { @@ -123,18 +124,15 @@ namespace basegfx bool B2DHomMatrix::invert() { Impl2DHomMatrix aWork(*mpImpl); - sal_uInt16* pIndex = new sal_uInt16[Impl2DHomMatrix_Base::getEdgeLength()]; + std::unique_ptr<sal_uInt16[]> pIndex( new sal_uInt16[Impl2DHomMatrix_Base::getEdgeLength()] ); sal_Int16 nParity; - if(aWork.ludcmp(pIndex, nParity)) + if(aWork.ludcmp(pIndex.get(), nParity)) { - mpImpl->doInvert(aWork, pIndex); - delete[] pIndex; - + mpImpl->doInvert(aWork, pIndex.get()); return true; } - delete[] pIndex; return false; } diff --git a/basegfx/source/matrix/b3dhommatrix.cxx b/basegfx/source/matrix/b3dhommatrix.cxx index e0c049c5bf55..919a00c9fb50 100644 --- a/basegfx/source/matrix/b3dhommatrix.cxx +++ b/basegfx/source/matrix/b3dhommatrix.cxx @@ -21,6 +21,7 @@ #include <basegfx/matrix/b3dhommatrix.hxx> #include <hommatrixtemplate.hxx> #include <basegfx/vector/b3dvector.hxx> +#include <memory> namespace basegfx { @@ -94,18 +95,15 @@ namespace basegfx bool B3DHomMatrix::invert() { Impl3DHomMatrix aWork(*mpImpl); - sal_uInt16* pIndex = new sal_uInt16[Impl3DHomMatrix_Base::getEdgeLength()]; + std::unique_ptr<sal_uInt16[]> pIndex( new sal_uInt16[Impl3DHomMatrix_Base::getEdgeLength()] ); sal_Int16 nParity; - if(aWork.ludcmp(pIndex, nParity)) + if(aWork.ludcmp(pIndex.get(), nParity)) { - mpImpl->doInvert(aWork, pIndex); - delete[] pIndex; - + mpImpl->doInvert(aWork, pIndex.get()); return true; } - delete[] pIndex; return false; } diff --git a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx index d79a53cf89e4..fa01a866a6dd 100644 --- a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx +++ b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx @@ -156,12 +156,12 @@ Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, co ScopedVclPtrInstance< VirtualDevice > pVDev; pVDev->SetMapMode(MapMode(MapUnit::Map100thMM)); - SdrModel* pModel = new SdrModel(); + std::unique_ptr<SdrModel> pModel( new SdrModel ); pModel->GetItemPool().FreezeIdRanges(); SdrPage* pPage = new SdrPage( *pModel, false ); pPage->SetSize(Size(1000,1000)); pModel->InsertPage( pPage, 0 ); - SdrView* pView = new SdrView( pModel, pVDev ); + std::unique_ptr<SdrView> pView( new SdrView( pModel.get(), pVDev ) ); pView->hideMarkHandles(); SdrPageView* pPageView = pView->ShowSdrPage(pPage); @@ -181,8 +181,6 @@ Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, co pView->UnmarkAll(); pObj=pPage->RemoveObject(0); SdrObject::Free( pObj ); - delete pView; - delete pModel; return aGraph; } diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 155fa0e2b568..a76f65d85afa 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -141,18 +141,23 @@ bool UseUniquePtr::VisitCompoundStmt(const CompoundStmt* compoundStmt) return true; } - const CXXDeleteExpr* deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_back()); + auto lastStmt = compoundStmt->body_back(); + if (compoundStmt->size() > 1) { + if (isa<ReturnStmt>(lastStmt)) + lastStmt = *(++compoundStmt->body_rbegin()); + } + auto deleteExpr = dyn_cast<CXXDeleteExpr>(lastStmt); if (deleteExpr == nullptr) { return true; } - const ImplicitCastExpr* pCastExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument()); + auto pCastExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument()); if (!pCastExpr) return true; - const DeclRefExpr* declRefExpr = dyn_cast<DeclRefExpr>(pCastExpr->getSubExpr()); + auto declRefExpr = dyn_cast<DeclRefExpr>(pCastExpr->getSubExpr()); if (!declRefExpr) return true; - const VarDecl* varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); + auto varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); if (!varDecl) return true; if (!varDecl->hasInit() || !dyn_cast<CXXNewExpr>(varDecl->getInit())) diff --git a/filter/source/msfilter/escherex.cxx b/filter/source/msfilter/escherex.cxx index 122dca177e20..7b8f679ffa7d 100644 --- a/filter/source/msfilter/escherex.cxx +++ b/filter/source/msfilter/escherex.cxx @@ -4196,7 +4196,7 @@ sal_uInt32 EscherGraphicProvider::GetBlibID( SvStream& rPicOutStrm, const OStrin sal_uInt32 nBlibId = 0; std::unique_ptr<GraphicObject> xGraphicObject(new GraphicObject(rId)); - EscherBlibEntry* p_EscherBlibEntry = new EscherBlibEntry( rPicOutStrm.Tell(), *xGraphicObject, rId, pGraphicAttr ); + std::unique_ptr<EscherBlibEntry> p_EscherBlibEntry( new EscherBlibEntry( rPicOutStrm.Tell(), *xGraphicObject, rId, pGraphicAttr ) ); if ( !p_EscherBlibEntry->IsEmpty() ) { for ( sal_uInt32 i = 0; i < mnBlibEntrys; i++ ) @@ -4204,7 +4204,6 @@ sal_uInt32 EscherGraphicProvider::GetBlibID( SvStream& rPicOutStrm, const OStrin if ( *( mpBlibEntrys[ i ] ) == *p_EscherBlibEntry ) { mpBlibEntrys[ i ]->mnRefCount++; - delete p_EscherBlibEntry; return i + 1; } } @@ -4433,11 +4432,9 @@ sal_uInt32 EscherGraphicProvider::GetBlibID( SvStream& rPicOutStrm, const OStrin rPicOutStrm.WriteUInt32( nPos - nAtomSize ); rPicOutStrm.Seek( nPos ); } - nBlibId = ImplInsertBlib( p_EscherBlibEntry ); - p_EscherBlibEntry = nullptr; + nBlibId = ImplInsertBlib( p_EscherBlibEntry.release() ); } } - delete p_EscherBlibEntry; return nBlibId; } diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx index 90fdfdbfe86c..3ab2b0087a6c 100644 --- a/hwpfilter/source/hwpfile.cxx +++ b/hwpfilter/source/hwpfile.cxx @@ -244,7 +244,7 @@ void HWPFile::ParaListRead() bool HWPFile::ReadParaList(std::list < HWPPara* > &aplist, unsigned char flag) { - HWPPara *spNode = new HWPPara; + std::unique_ptr<HWPPara> spNode( new HWPPara ); unsigned char tmp_etcflag; unsigned char prev_etcflag = 0; while (spNode->Read(*this, flag)) @@ -269,11 +269,10 @@ bool HWPFile::ReadParaList(std::list < HWPPara* > &aplist, unsigned char flag) AddParaShape( &spNode->pshape ); if (!aplist.empty()) - aplist.back()->SetNext(spNode); - aplist.push_back(spNode); - spNode = new HWPPara; + aplist.back()->SetNext(spNode.get()); + aplist.push_back(spNode.release()); + spNode.reset( new HWPPara ); } - delete spNode; return true; } diff --git a/hwpfilter/source/solver.cxx b/hwpfilter/source/solver.cxx index 144e11c3858a..f297160159f1 100644 --- a/hwpfilter/source/solver.cxx +++ b/hwpfilter/source/solver.cxx @@ -18,6 +18,7 @@ */ #include <math.h> +#include <memory> #include "solver.h" @@ -63,18 +64,15 @@ double* mgcLinearSystemD::NewVector (int N) int mgcLinearSystemD::Solve (int n, double** a, double* b) { - int* indxc = new int[n]; + std::unique_ptr<int[]> indxc( new int[n] ); if ( !indxc ) return 0; - int* indxr = new int[n]; + std::unique_ptr<int[]> indxr( new int[n] ); if ( !indxr ) { - delete[] indxc; return 0; } - int* ipiv = new int[n]; + std::unique_ptr<int[]> ipiv( new int[n] ); if ( !ipiv ) { - delete[] indxc; - delete[] indxr; return 0; } @@ -93,26 +91,23 @@ int mgcLinearSystemD::Solve (int n, double** a, double* b) { if ( ipiv[j] != 1 ) { - for (k = 0; k < n; k++) - { - if ( ipiv[k] == 0 ) - { - if ( fabs(a[j][k]) >= big ) + for (k = 0; k < n; k++) { - big = fabs(a[j][k]); - irow = j; - icol = k; + if ( ipiv[k] == 0 ) + { + if ( fabs(a[j][k]) >= big ) + { + big = fabs(a[j][k]); + irow = j; + icol = k; + } + } + else if ( ipiv[k] > 1 ) + { + return 0; + } } } - else if ( ipiv[k] > 1 ) - { - delete[] ipiv; - delete[] indxr; - delete[] indxc; - return 0; - } - } - } } ipiv[icol]++; @@ -131,9 +126,6 @@ int mgcLinearSystemD::Solve (int n, double** a, double* b) indxc[i] = icol; if ( a[icol][icol] == 0 ) { - delete[] ipiv; - delete[] indxr; - delete[] indxc; return 0; } @@ -162,16 +154,13 @@ int mgcLinearSystemD::Solve (int n, double** a, double* b) { for (k = 0; k < n; k++) { - save = a[k][indxr[j]]; - a[k][indxr[j]] = a[k][indxc[j]]; - a[k][indxc[j]] = save; + save = a[k][indxr[j]]; + a[k][indxr[j]] = a[k][indxc[j]]; + a[k][indxc[j]] = save; } } } - delete[] ipiv; - delete[] indxr; - delete[] indxc; return 1; } diff --git a/lotuswordpro/source/filter/lwpnumericfmt.cxx b/lotuswordpro/source/filter/lwpnumericfmt.cxx index 54a186fd1676..9653b095b77e 100644 --- a/lotuswordpro/source/filter/lwpnumericfmt.cxx +++ b/lotuswordpro/source/filter/lwpnumericfmt.cxx @@ -374,7 +374,7 @@ OUString LwpNumericFormat::reencode(const OUString& sCode) sal_uInt16 nLen = sCode.getLength(); bool bFound = false; sal_uInt16 i; - sal_Unicode *pBuff = new sal_Unicode[sCode.getLength()]; + std::unique_ptr<sal_Unicode[]> pBuff( new sal_Unicode[sCode.getLength()] ); for (i=0; i< sCode.getLength() - 1; i++) { @@ -392,12 +392,10 @@ OUString LwpNumericFormat::reencode(const OUString& sCode) { pBuff[j] = pString[j+1]; } - OUString sRet(pBuff, nLen - 1); - delete [] pBuff; + OUString sRet(pBuff.get(), nLen - 1); return sRet; } - delete [] pBuff; return sCode; } diff --git a/lotuswordpro/source/filter/lwptablelayout.cxx b/lotuswordpro/source/filter/lwptablelayout.cxx index dc0c56b523be..ad7b987ad7ec 100644 --- a/lotuswordpro/source/filter/lwptablelayout.cxx +++ b/lotuswordpro/source/filter/lwptablelayout.cxx @@ -844,13 +844,13 @@ sal_uInt16 LwpTableLayout::ConvertHeadingRow( { sal_uInt16 nContentRow; sal_uInt8 nCol = static_cast<sal_uInt8>(GetTable()->GetColumn()); - XFTable* pTmpTable = new XFTable; + rtl::Reference<XFTable> pTmpTable( new XFTable ); XFRow* pXFRow; - ConvertTable(pTmpTable,nStartHeadRow,nEndHeadRow,0,nCol); + ConvertTable(pTmpTable.get(),nStartHeadRow,nEndHeadRow,0,nCol); sal_uInt16 nRowNum = pTmpTable->GetRowCount(); - sal_uInt8* CellMark = new sal_uInt8[nRowNum]; + std::unique_ptr<sal_uInt8[]> CellMark( new sal_uInt8[nRowNum] ); if (nRowNum == 1) { @@ -862,11 +862,11 @@ sal_uInt16 LwpTableLayout::ConvertHeadingRow( else { sal_uInt8 nFirstColSpann = 1; - const bool bFindFlag = FindSplitColMark(pTmpTable,CellMark,nFirstColSpann); + const bool bFindFlag = FindSplitColMark(pTmpTable.get(),CellMark.get(),nFirstColSpann); if (bFindFlag)//split to 2 cells { - SplitRowToCells(pTmpTable,pXFTable,nFirstColSpann,CellMark); + SplitRowToCells(pTmpTable.get(),pXFTable,nFirstColSpann,CellMark.get()); nContentRow = nEndHeadRow; } else//can not split,the first row will be the heading row,the rest will be content row @@ -877,8 +877,6 @@ sal_uInt16 LwpTableLayout::ConvertHeadingRow( nContentRow = m_RowsMap[0]->GetCurMaxSpannedRows(0,nCol); } } - delete pTmpTable; - delete [] CellMark; return nContentRow; } diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx index b3e208538b0a..a0dc97b7553a 100644 --- a/sc/source/core/data/patattr.cxx +++ b/sc/source/core/data/patattr.cxx @@ -1076,7 +1076,7 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcD { const SfxItemSet* pSrcSet = &GetItemSet(); - ScPatternAttr* pDestPattern = new ScPatternAttr(pDestDoc->GetPool()); + std::unique_ptr<ScPatternAttr> pDestPattern( new ScPatternAttr(pDestDoc->GetPool()) ); SfxItemSet* pDestSet = &pDestPattern->GetItemSet(); // Copy cell pattern style to other document: @@ -1144,7 +1144,6 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcD ScPatternAttr* pPatternAttr = const_cast<ScPatternAttr*>( static_cast<const ScPatternAttr*>( &pDestDoc->GetPool()->Put(*pDestPattern) ) ); - delete pDestPattern; return pPatternAttr; } diff --git a/sc/source/filter/qpro/qpro.cxx b/sc/source/filter/qpro/qpro.cxx index f6cc4712f457..97b2081cdde1 100644 --- a/sc/source/filter/qpro/qpro.cxx +++ b/sc/source/filter/qpro/qpro.cxx @@ -162,7 +162,7 @@ FltError ScQProReader::import( ScDocument *pDoc ) if( !recordsLeft() ) return eERR_OPEN; - ScQProStyle *pStyleElement = new ScQProStyle; + std::unique_ptr<ScQProStyle> pStyleElement( new ScQProStyle ); while( nextRecord() && eRet == eERR_OK) { @@ -184,7 +184,7 @@ FltError ScQProReader::import( ScDocument *pDoc ) else pDoc->InsertTab( nTab, aName ); } - eRet = readSheet( nTab, pDoc, pStyleElement ); + eRet = readSheet( nTab, pDoc, pStyleElement.get() ); nTab++; } break; @@ -220,7 +220,6 @@ FltError ScQProReader::import( ScDocument *pDoc ) } } pDoc->CalcAfterLoad(); - delete pStyleElement; return eRet; } diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index f0ab4dd1c006..47ea37a8dc8d 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -2130,11 +2130,11 @@ bool ScImportExport::Doc2Dif( SvStream& rStrm ) bool ScImportExport::Dif2Doc( SvStream& rStrm ) { SCTAB nTab = aRange.aStart.Tab(); - ScDocument* pImportDoc = new ScDocument( SCDOCMODE_UNDO ); + std::unique_ptr<ScDocument> pImportDoc( new ScDocument( SCDOCMODE_UNDO ) ); pImportDoc->InitUndo( pDoc, nTab, nTab ); // for DIF in the clipboard, IBM_850 is always used - ScFormatFilter::Get().ScImportDif( rStrm, pImportDoc, aRange.aStart, RTL_TEXTENCODING_IBM_850 ); + ScFormatFilter::Get().ScImportDif( rStrm, pImportDoc.get(), aRange.aStart, RTL_TEXTENCODING_IBM_850 ); SCCOL nEndCol; SCROW nEndRow; @@ -2155,8 +2155,6 @@ bool ScImportExport::Dif2Doc( SvStream& rStrm ) EndPaste(); } - delete pImportDoc; - return bOk; } diff --git a/sd/source/ui/unoidl/unosrch.cxx b/sd/source/ui/unoidl/unosrch.cxx index cd59a07b3dd5..a24f235ecde6 100644 --- a/sd/source/ui/unoidl/unosrch.cxx +++ b/sd/source/ui/unoidl/unosrch.cxx @@ -469,13 +469,13 @@ uno::Reference< text::XTextRange > SdUnoSearchReplaceShape::Search( const uno:: const sal_Int32 nTextLen = aText.getLength(); - sal_Int32* pConvertPos = new sal_Int32[nTextLen+2]; - sal_Int32* pConvertPara = new sal_Int32[nTextLen+2]; + std::unique_ptr<sal_Int32[]> pConvertPos( new sal_Int32[nTextLen+2] ); + std::unique_ptr<sal_Int32[]> pConvertPara( new sal_Int32[nTextLen+2] ); const sal_Unicode* pText = aText.getStr(); - sal_Int32* pPos = pConvertPos; - sal_Int32* pPara = pConvertPara; + sal_Int32* pPos = pConvertPos.get(); + sal_Int32* pPara = pConvertPara.get(); sal_Int32 nLastPos = 0, nLastPara = 0; @@ -614,9 +614,6 @@ uno::Reference< text::XTextRange > SdUnoSearchReplaceShape::Search( const uno:: } } - delete[] pConvertPos; - delete[] pConvertPara; - return xFound; } 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; } diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index d2de88e44d3e..d30c5e0bf125 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -1003,15 +1003,14 @@ SvStream& SvStream::ReadDouble(double& r) SvStream& SvStream::ReadStream( SvStream& rStream ) { const sal_uInt32 cBufLen = 0x8000; - char* pBuf = new char[ cBufLen ]; + std::unique_ptr<char[]> pBuf( new char[ cBufLen ] ); sal_uInt32 nCount; do { - nCount = ReadBytes( pBuf, cBufLen ); - rStream.WriteBytes( pBuf, nCount ); + nCount = ReadBytes( pBuf.get(), cBufLen ); + rStream.WriteBytes( pBuf.get(), nCount ); } while( nCount == cBufLen ); - delete[] pBuf; return *this; } @@ -1166,14 +1165,13 @@ SvStream& SvStream::WriteCharPtr( const char* pBuf ) SvStream& SvStream::WriteStream( SvStream& rStream ) { const sal_uInt32 cBufLen = 0x8000; - char* pBuf = new char[ cBufLen ]; + std::unique_ptr<char[]> pBuf( new char[ cBufLen ] ); sal_uInt32 nCount; do { - nCount = rStream.ReadBytes( pBuf, cBufLen ); - WriteBytes( pBuf, nCount ); + nCount = rStream.ReadBytes( pBuf.get(), cBufLen ); + WriteBytes( pBuf.get(), nCount ); } while( nCount == cBufLen ); - delete[] pBuf; return *this; } |