From 3f20471490c61b19fe4222f8c40df255051f6e3d Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 14 Jun 2017 15:58:42 +0200 Subject: use std::unique_ptr in FlatFndBox and extend o3tl::make_unique to cope with arrays Change-Id: I84caa46ab5060f9777bfe275f229499cb0b407be Reviewed-on: https://gerrit.libreoffice.org/38794 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/source/core/doc/docsort.cxx | 12 ++++-------- sw/source/core/inc/docsort.hxx | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'sw') diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index d71f9a079426..f2c02f409342 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -747,7 +747,6 @@ void MoveCell(SwDoc* pDoc, const SwTableBox* pSource, const SwTableBox* pTar, FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) : pDoc(pDocPtr), rBoxRef(rBox), - pArr(nullptr), nRow(0), nCol(0) { // If the array is symmetric @@ -760,9 +759,8 @@ FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) : // Create linear array size_t nCount = static_cast(nRows) * nCols; - pArr = new const FndBox_*[nCount]; - FndBox_** ppTmp = const_cast(pArr); - memset(ppTmp, 0, sizeof(const FndBox_*) * nCount); + pArr = o3tl::make_unique(nCount); + memset(pArr.get(), 0, sizeof(const FndBox_*) * nCount); FillFlat( rBoxRef ); } @@ -770,8 +768,6 @@ FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) : FlatFndBox::~FlatFndBox() { - FndBox_** ppTmp = const_cast(pArr); - delete [] ppTmp; } /// All Lines of a Box need to have same number of Boxes @@ -890,7 +886,7 @@ void FlatFndBox::FillFlat(const FndBox_& rBox, bool bLastBox) { // save it sal_uInt16 nOff = nRow * nCols + nCol; - *(pArr + nOff) = pBox; + pArr[nOff] = pBox; // Save the Formula/Format/Value values const SwFrameFormat* pFormat = pBox->GetBox()->GetFrameFormat(); @@ -931,7 +927,7 @@ void FlatFndBox::FillFlat(const FndBox_& rBox, bool bLastBox) const FndBox_* FlatFndBox::GetBox(sal_uInt16 n_Col, sal_uInt16 n_Row) const { sal_uInt16 nOff = n_Row * nCols + n_Col; - const FndBox_* pTmp = *(pArr + nOff); + const FndBox_* pTmp = pArr[nOff]; OSL_ENSURE(n_Col < nCols && n_Row < nRows && pTmp, "invalid array access"); return pTmp; diff --git a/sw/source/core/inc/docsort.hxx b/sw/source/core/inc/docsort.hxx index f8c1990ef9a3..b66ecd3f5159 100644 --- a/sw/source/core/inc/docsort.hxx +++ b/sw/source/core/inc/docsort.hxx @@ -140,7 +140,7 @@ private: SwDoc* pDoc; const FndBox_& rBoxRef; - const FndBox_** pArr; + std::unique_ptr pArr; std::vector> ppItemSets; sal_uInt16 nRows; -- cgit