Skip to content

Commit

Permalink
extend loplugin useuniqueptr to OUString pointers
Browse files Browse the repository at this point in the history
Change-Id: Ieb5bab3895e1edaff497c4a1a88303ccac097edc
Reviewed-on: https://gerrit.libreoffice.org/39948
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
  • Loading branch information
Noel Grandin committed Jul 17, 2017
1 parent 846f557 commit db38600
Show file tree
Hide file tree
Showing 32 changed files with 170 additions and 230 deletions.
Expand Up @@ -89,8 +89,6 @@ OfficeInstallationDirectories::OfficeInstallationDirectories(
// virtual
OfficeInstallationDirectories::~OfficeInstallationDirectories()
{
delete m_pOfficeBrandDir;
delete m_pUserDir;
}


Expand Down Expand Up @@ -216,8 +214,8 @@ void OfficeInstallationDirectories::initDirs()
osl::MutexGuard aGuard( m_aMutex );
if ( m_pOfficeBrandDir == nullptr )
{
m_pOfficeBrandDir = new OUString;
m_pUserDir = new OUString;
m_pOfficeBrandDir.reset( new OUString );
m_pUserDir.reset( new OUString );

uno::Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(m_xCtx);

Expand Down
Expand Up @@ -26,6 +26,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
#include <memory>

namespace comphelper {

Expand Down Expand Up @@ -71,8 +72,8 @@ private:
OUString m_aOfficeBrandDirMacro;
OUString m_aUserDirMacro;
css::uno::Reference< css::uno::XComponentContext > m_xCtx;
OUString * m_pOfficeBrandDir;
OUString * m_pUserDir;
std::unique_ptr<OUString> m_pOfficeBrandDir;
std::unique_ptr<OUString> m_pUserDir;
};

} // namespace comphelper
Expand Down
6 changes: 5 additions & 1 deletion compilerplugins/clang/useuniqueptr.cxx
Expand Up @@ -14,6 +14,7 @@
#include <fstream>
#include <set>
#include "plugin.hxx"
#include "check.hxx"

/**
Find destructors that only contain a single call to delete of a field. In which
Expand Down Expand Up @@ -221,7 +222,10 @@ void UseUniquePtr::CheckForDeleteOfPOD(const CompoundStmt* compoundStmt)

auto pointerType = dyn_cast<PointerType>(fieldDecl->getType()->getUnqualifiedDesugaredType());
QualType elementType = pointerType->getPointeeType();
if (!elementType.isPODType(compiler.getASTContext()))
auto tc = loplugin::TypeCheck(elementType);
if (!elementType.isPODType(compiler.getASTContext())
&& !tc.Class("OUString").Namespace("rtl").GlobalNamespace()
&& !tc.Class("OString").Namespace("rtl").GlobalNamespace())
continue;

StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart()));
Expand Down
3 changes: 2 additions & 1 deletion idlc/inc/astexpression.hxx
Expand Up @@ -131,7 +131,8 @@ private:
AstExpression* m_subExpr2;
std::unique_ptr<AstExprValue>
m_exprValue;
OString* m_pSymbolicName;
std::unique_ptr<OString>
m_pSymbolicName;
};

#endif // INCLUDED_IDLC_INC_ASTEXPRESSION_HXX
Expand Down
1 change: 0 additions & 1 deletion idlc/source/astexpression.cxx
Expand Up @@ -125,7 +125,6 @@ AstExpression::~AstExpression()
{
delete m_subExpr1;
delete m_subExpr2;
delete m_pSymbolicName;
}

/*
Expand Down
6 changes: 2 additions & 4 deletions lingucomponent/source/spellcheck/spell/sspellimp.cxx
Expand Up @@ -89,7 +89,6 @@ SpellChecker::~SpellChecker()
delete[] m_aDicts;
}
delete[] m_aDLocs;
delete[] m_aDNames;
if (m_pPropHelper)
{
m_pPropHelper->RemoveAsPropListener();
Expand Down Expand Up @@ -201,7 +200,7 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
m_aDicts = new Hunspell* [m_nNumDict];
m_aDEncs.reset( new rtl_TextEncoding [m_nNumDict] );
m_aDLocs = new Locale [m_nNumDict];
m_aDNames = new OUString [m_nNumDict];
m_aDNames.reset( new OUString [m_nNumDict] );
k = 0;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
{
Expand Down Expand Up @@ -242,8 +241,7 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
m_aDEncs.reset();
delete[] m_aDLocs;
m_aDLocs = nullptr;
delete[] m_aDNames;
m_aDNames = nullptr;
m_aDNames.reset();
m_aSuppLocales.realloc(0);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lingucomponent/source/spellcheck/spell/sspellimp.hxx
Expand Up @@ -58,7 +58,7 @@ class SpellChecker :
Hunspell ** m_aDicts;
std::unique_ptr<rtl_TextEncoding[]> m_aDEncs;
Locale * m_aDLocs;
OUString * m_aDNames;
std::unique_ptr<OUString[]> m_aDNames;
sal_Int32 m_nNumDict;

::comphelper::OInterfaceContainerHelper2 m_aEvtListeners;
Expand Down
4 changes: 2 additions & 2 deletions sc/inc/chartarr.hxx
Expand Up @@ -37,8 +37,8 @@ class ScMemChart
SCROW nRowCnt;
SCCOL nColCnt;
std::unique_ptr<double[]> pData;
OUString* pColText;
OUString* pRowText;
std::unique_ptr<OUString[]> pColText;
std::unique_ptr<OUString[]> pRowText;

ScMemChart(const ScMemChart& rMemChart) = delete;

Expand Down
6 changes: 2 additions & 4 deletions sc/source/core/tool/chartarr.cxx
Expand Up @@ -47,14 +47,12 @@ ScMemChart::ScMemChart(SCCOL nCols, SCROW nRows)

memset( pData.get(), 0.0, nColCnt * nRowCnt );

pColText = new OUString[nColCnt];
pRowText = new OUString[nRowCnt];
pColText.reset( new OUString[nColCnt] );
pRowText.reset( new OUString[nRowCnt] );
}

ScMemChart::~ScMemChart()
{
delete[] pRowText;
delete[] pColText;
}

ScChartArray::ScChartArray( ScDocument* pDoc, SCTAB nTab,
Expand Down
10 changes: 5 additions & 5 deletions sc/source/filter/html/htmlpars.cxx
Expand Up @@ -1012,12 +1012,12 @@ void ScHTMLLayoutParser::TableDataOn( HtmlImportInfo* pInfo )
break;
case HtmlOptionId::SDVAL:
{
pActEntry->pValStr = new OUString( rOption.GetString() );
pActEntry->pValStr.reset( new OUString( rOption.GetString() ) );
}
break;
case HtmlOptionId::SDNUM:
{
pActEntry->pNumStr = new OUString( rOption.GetString() );
pActEntry->pNumStr.reset( new OUString( rOption.GetString() ) );
}
break;
default: break;
Expand Down Expand Up @@ -1453,7 +1453,7 @@ void ScHTMLLayoutParser::AnchorOn( HtmlImportInfo* pInfo )
for (const auto & rOption : rOptions)
{
if( rOption.GetToken() == HtmlOptionId::NAME )
pActEntry->pName = new OUString(rOption.GetString());
pActEntry->pName.reset( new OUString(rOption.GetString()) );
}
}

Expand Down Expand Up @@ -2160,8 +2160,8 @@ void ScHTMLTable::DataOn( const HtmlImportInfo& rInfo )

ProcessFormatOptions( *mxDataItemSet, rInfo );
CreateNewEntry( rInfo );
mxCurrEntry->pValStr = pValStr.release();
mxCurrEntry->pNumStr = pNumStr.release();
mxCurrEntry->pValStr.reset( pValStr.release() );
mxCurrEntry->pNumStr.reset( pNumStr.release() );
}
else
CreateNewEntry( rInfo );
Expand Down
12 changes: 6 additions & 6 deletions sc/source/filter/inc/eeparser.hxx
Expand Up @@ -51,9 +51,12 @@ struct ScEEParseEntry
{
SfxItemSet aItemSet;
ESelection aSel; // Selection in EditEngine
OUString* pValStr; // HTML possibly SDVAL string
OUString* pNumStr; // HTML possibly SDNUM string
OUString* pName; // HTML possibly anchor/RangeName
std::unique_ptr<OUString>
pValStr; // HTML possibly SDVAL string
std::unique_ptr<OUString>
pNumStr; // HTML possibly SDNUM string
std::unique_ptr<OUString>
pName; // HTML possibly anchor/RangeName
OUString aAltText; // HTML IMG ALT Text
std::vector< std::unique_ptr<ScHTMLImage> > maImageList; // graphics in this cell
SCCOL nCol; // relative to the beginning of the parse
Expand Down Expand Up @@ -85,9 +88,6 @@ struct ScEEParseEntry

~ScEEParseEntry()
{
delete pValStr;
delete pNumStr;
delete pName;
maImageList.clear();
}
};
Expand Down
37 changes: 12 additions & 25 deletions sc/source/filter/xml/XMLStylesImportHelper.cxx
Expand Up @@ -250,21 +250,13 @@ ScMyStylesImportHelper::ScMyStylesImportHelper(ScXMLImport& rTempImport)

ScMyStylesImportHelper::~ScMyStylesImportHelper()
{
delete pPrevStyleName;
delete pPrevCurrency;
delete pStyleName;
delete pCurrency;
}

void ScMyStylesImportHelper::ResetAttributes()
{
delete pPrevStyleName;
delete pPrevCurrency;
pPrevStyleName = pStyleName;
pPrevCurrency = pCurrency;
pPrevStyleName.reset( pStyleName.release() );
pPrevCurrency.reset( pCurrency.release() );
nPrevCellType = nCellType;
pStyleName = nullptr;
pCurrency = nullptr;
nCellType = 0;
}

Expand Down Expand Up @@ -311,8 +303,7 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
ScRange aRange(rRange);
aRange.aStart.SetCol(nStartCol);
aRange.aEnd.SetCol(i - 1);
delete pPrevStyleName;
pPrevStyleName = new OUString(aPrevItr->sStyleName);
pPrevStyleName.reset( new OUString(aPrevItr->sStyleName) );
AddSingleRange(aRange);
nStartCol = i;
aPrevItr = aColDefaultStyles[i];
Expand All @@ -322,8 +313,7 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
{
ScRange aRange(rRange);
aRange.aStart.SetCol(nStartCol);
delete pPrevStyleName;
pPrevStyleName = new OUString(aPrevItr->sStyleName);
pPrevStyleName.reset( new OUString(aPrevItr->sStyleName) );
AddSingleRange(aRange);
}
else
Expand All @@ -338,21 +328,20 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
}
else
{
delete pPrevStyleName;
pPrevStyleName = new OUString(aRowDefaultStyle->sStyleName);
pPrevStyleName.reset( new OUString(aRowDefaultStyle->sStyleName) );
AddSingleRange(rRange);
}
}

void ScMyStylesImportHelper::AddSingleRange(const ScRange& rRange)
{
ScMyStylesSet::iterator aItr(GetIterator(pPrevStyleName));
ScMyStylesSet::iterator aItr(GetIterator(pPrevStyleName.get()));
if (aItr != aCellStyles.end())
{
if (nPrevCellType != util::NumberFormat::CURRENCY)
aItr->xRanges->AddRange(rRange, nPrevCellType);
else
aItr->xRanges->AddCurrencyRange(rRange, pPrevCurrency);
aItr->xRanges->AddCurrencyRange(rRange, pPrevCurrency.get());
}
}

Expand Down Expand Up @@ -383,11 +372,9 @@ void ScMyStylesImportHelper::SetRowStyle(const OUString& sStyleName)
void ScMyStylesImportHelper::SetAttributes(OUString* pStyleNameP,
OUString* pCurrencyP, const sal_Int16 nCellTypeP)
{
delete this->pStyleName;
delete this->pCurrency;
this->pStyleName = pStyleNameP;
this->pCurrency = pCurrencyP;
this->nCellType = nCellTypeP;
pStyleName.reset( pStyleNameP );
pCurrency.reset( pCurrencyP );
nCellType = nCellTypeP;
}

void ScMyStylesImportHelper::AddRange(const ScRange& rRange)
Expand All @@ -396,8 +383,8 @@ void ScMyStylesImportHelper::AddRange(const ScRange& rRange)
{
bool bAddRange(false);
if (nCellType == nPrevCellType &&
IsEqual(pStyleName, pPrevStyleName) &&
IsEqual(pCurrency, pPrevCurrency))
IsEqual(pStyleName.get(), pPrevStyleName.get()) &&
IsEqual(pCurrency.get(), pPrevCurrency.get()))
{
if (rRange.aStart.Row() == aPrevRange.aStart.Row())
{
Expand Down
12 changes: 8 additions & 4 deletions sc/source/filter/xml/XMLStylesImportHelper.hxx
Expand Up @@ -128,10 +128,14 @@ class ScMyStylesImportHelper
std::vector<ScMyStylesSet::iterator> aColDefaultStyles;
ScMyStylesSet::iterator aRowDefaultStyle;
ScXMLImport& rImport;
OUString* pStyleName;
OUString* pPrevStyleName;
OUString* pCurrency;
OUString* pPrevCurrency;
std::unique_ptr<OUString>
pStyleName;
std::unique_ptr<OUString>
pPrevStyleName;
std::unique_ptr<OUString>
pCurrency;
std::unique_ptr<OUString>
pPrevCurrency;
ScRange aPrevRange;
sal_Int16 nCellType;
sal_Int16 nPrevCellType;
Expand Down
9 changes: 5 additions & 4 deletions svgio/inc/svgnode.hxx
Expand Up @@ -25,6 +25,7 @@
#include <svgpaint.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <com/sun/star/xml/sax/XAttributeList.hpp>
#include <memory>
#include <vector>

// predefines
Expand Down Expand Up @@ -94,10 +95,10 @@ namespace svgio
SvgNodeVector maChildren;

/// Id svan value
OUString* mpId;
std::unique_ptr<OUString> mpId;

/// Class svan value
OUString* mpClass;
std::unique_ptr<OUString> mpClass;

/// XmlSpace value
XmlSpace maXmlSpace;
Expand Down Expand Up @@ -163,11 +164,11 @@ namespace svgio
double getCurrentXHeight() const;

/// Id access
const OUString* getId() const { return mpId; }
const OUString* getId() const { return mpId.get(); }
void setId(const OUString* pfId);

/// Class access
const OUString* getClass() const { return mpClass; }
const OUString* getClass() const { return mpClass.get(); }
void setClass(const OUString* pfClass);

/// XmlSpace access
Expand Down
12 changes: 4 additions & 8 deletions svgio/source/svgreader/svgnode.cxx
Expand Up @@ -296,8 +296,6 @@ namespace svgio
maChildren.pop_back();
}

delete mpId;
delete mpClass;
delete mpLocalCssStyle;
}

Expand Down Expand Up @@ -643,13 +641,12 @@ namespace svgio
if(mpId)
{
mrDocument.removeSvgNodeFromMapper(*mpId);
delete mpId;
mpId = nullptr;
mpId.reset();
}

if(pfId)
{
mpId = new OUString(*pfId);
mpId.reset( new OUString(*pfId) );
mrDocument.addSvgNodeToMapper(*mpId, *this);
}
}
Expand All @@ -659,13 +656,12 @@ namespace svgio
if(mpClass)
{
mrDocument.removeSvgNodeFromMapper(*mpClass);
delete mpClass;
mpClass = nullptr;
mpClass.reset();
}

if(pfClass)
{
mpClass = new OUString(*pfClass);
mpClass.reset( new OUString(*pfClass) );
mrDocument.addSvgNodeToMapper(*mpClass, *this);
}
}
Expand Down

0 comments on commit db38600

Please sign in to comment.