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 /sc | |
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 'sc')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/callform.cxx | 125 | ||||
-rw-r--r-- | sc/source/filter/starcalc/scflt.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/unoobj/funcuno.cxx | 8 |
4 files changed, 68 insertions, 76 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 81bc4152b9dc..f5871f7aa339 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -5989,7 +5989,7 @@ void testDataBarLengthImpl(ScDocument* pDoc, ScDataBarLengthData* pData, const S double nMaxVal, ScColorScaleEntryType eMaxType, double nZeroPos, databar::ScAxisPosition eAxisPos) { - ScConditionalFormat* pFormat = new ScConditionalFormat(1, pDoc); + std::unique_ptr<ScConditionalFormat> pFormat(new ScConditionalFormat(1, pDoc)); ScRangeList aRangeList(rRange); pFormat->SetRange(aRangeList); @@ -6021,7 +6021,6 @@ void testDataBarLengthImpl(ScDocument* pDoc, ScDataBarLengthData* pData, const S ASSERT_DOUBLES_EQUAL(pData[i].nLength, xInfo->mnLength); ASSERT_DOUBLES_EQUAL(nZeroPos, xInfo->mnZero); } - delete pFormat; } } diff --git a/sc/source/core/tool/callform.cxx b/sc/source/core/tool/callform.cxx index a859c3ccada1..3334715acf97 100644 --- a/sc/source/core/tool/callform.cxx +++ b/sc/source/core/tool/callform.cxx @@ -25,6 +25,7 @@ #include <osl/module.hxx> #include <osl/file.hxx> #include <unotools/transliterationwrapper.hxx> +#include <memory> #include "callform.hxx" #include "global.hxx" @@ -170,75 +171,69 @@ bool InitExternalFunc(const OUString& rModuleName) OUString aNP; aNP = rModuleName; - bool bRet = false; - osl::Module* pLib = new osl::Module( aNP ); - if (pLib->is()) + std::unique_ptr<osl::Module> pLib(new osl::Module( aNP )); + if (!pLib->is()) + return false; + + oslGenericFunction fpGetCount = pLib->getFunctionSymbol(GETFUNCTIONCOUNT); + oslGenericFunction fpGetData = pLib->getFunctionSymbol(GETFUNCTIONDATA); + if ((fpGetCount == nullptr) || (fpGetData == nullptr)) + return false; + + oslGenericFunction fpIsAsync = pLib->getFunctionSymbol(ISASYNC); + oslGenericFunction fpAdvice = pLib->getFunctionSymbol(ADVICE); + oslGenericFunction fpSetLanguage = pLib->getFunctionSymbol(SETLANGUAGE); + if ( fpSetLanguage ) { - oslGenericFunction fpGetCount = pLib->getFunctionSymbol(GETFUNCTIONCOUNT); - oslGenericFunction fpGetData = pLib->getFunctionSymbol(GETFUNCTIONDATA); - if ((fpGetCount != nullptr) && (fpGetData != nullptr)) + LanguageType eLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType(); + sal_uInt16 nLanguage = (sal_uInt16) eLanguage; + (*reinterpret_cast<SetLanguagePtr>(fpSetLanguage))( nLanguage ); + } + + // Module in die Collection aufnehmen + ModuleData* pModuleData = new ModuleData(rModuleName, pLib.release()); + aModuleCollection.insert(pModuleData); + + // Schnittstelle initialisieren + AdvData pfCallBack = &ScAddInAsyncCallBack; + LegacyFuncCollection* pLegacyFuncCol = ScGlobal::GetLegacyFuncCollection(); + sal_uInt16 nCount; + (*reinterpret_cast<GetFuncCountPtr>(fpGetCount))(nCount); + for (sal_uInt16 i=0; i < nCount; i++) + { + sal_Char cFuncName[256]; + sal_Char cInternalName[256]; + sal_uInt16 nParamCount; + ParamType eParamType[MAXFUNCPARAM]; + ParamType eAsyncType = ParamType::NONE; + // initialize all, in case the AddIn behaves bad + cFuncName[0] = 0; + cInternalName[0] = 0; + nParamCount = 0; + for ( sal_uInt16 j=0; j<MAXFUNCPARAM; j++ ) { - oslGenericFunction fpIsAsync = pLib->getFunctionSymbol(ISASYNC); - oslGenericFunction fpAdvice = pLib->getFunctionSymbol(ADVICE); - oslGenericFunction fpSetLanguage = pLib->getFunctionSymbol(SETLANGUAGE); - if ( fpSetLanguage ) - { - LanguageType eLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType(); - sal_uInt16 nLanguage = (sal_uInt16) eLanguage; - (*reinterpret_cast<SetLanguagePtr>(fpSetLanguage))( nLanguage ); - } - - // Module in die Collection aufnehmen - ModuleData* pModuleData = new ModuleData(rModuleName, pLib); - aModuleCollection.insert(pModuleData); - - // Schnittstelle initialisieren - AdvData pfCallBack = &ScAddInAsyncCallBack; - LegacyFuncCollection* pLegacyFuncCol = ScGlobal::GetLegacyFuncCollection(); - sal_uInt16 nCount; - (*reinterpret_cast<GetFuncCountPtr>(fpGetCount))(nCount); - for (sal_uInt16 i=0; i < nCount; i++) - { - sal_Char cFuncName[256]; - sal_Char cInternalName[256]; - sal_uInt16 nParamCount; - ParamType eParamType[MAXFUNCPARAM]; - ParamType eAsyncType = ParamType::NONE; - // initialize all, in case the AddIn behaves bad - cFuncName[0] = 0; - cInternalName[0] = 0; - nParamCount = 0; - for ( sal_uInt16 j=0; j<MAXFUNCPARAM; j++ ) - { - eParamType[j] = ParamType::NONE; - } - (*reinterpret_cast<GetFuncDataPtr>(fpGetData))(i, cFuncName, nParamCount, - eParamType, cInternalName); - if( fpIsAsync ) - { - (*reinterpret_cast<IsAsync>(fpIsAsync))(i, &eAsyncType); - if ( fpAdvice && eAsyncType != ParamType::NONE ) - (*reinterpret_cast<Advice>(fpAdvice))( i, pfCallBack ); - } - OUString aInternalName( cInternalName, strlen(cInternalName), osl_getThreadTextEncoding() ); - OUString aFuncName( cFuncName, strlen(cFuncName), osl_getThreadTextEncoding() ); - LegacyFuncData* pLegacyFuncData = new LegacyFuncData( pModuleData, - aInternalName, - aFuncName, - i, - nParamCount, - eParamType, - eAsyncType ); - pLegacyFuncCol->insert(pLegacyFuncData); - } - bRet = true; + eParamType[j] = ParamType::NONE; } - else - delete pLib; + (*reinterpret_cast<GetFuncDataPtr>(fpGetData))(i, cFuncName, nParamCount, + eParamType, cInternalName); + if( fpIsAsync ) + { + (*reinterpret_cast<IsAsync>(fpIsAsync))(i, &eAsyncType); + if ( fpAdvice && eAsyncType != ParamType::NONE ) + (*reinterpret_cast<Advice>(fpAdvice))( i, pfCallBack ); + } + OUString aInternalName( cInternalName, strlen(cInternalName), osl_getThreadTextEncoding() ); + OUString aFuncName( cFuncName, strlen(cFuncName), osl_getThreadTextEncoding() ); + LegacyFuncData* pLegacyFuncData = new LegacyFuncData( pModuleData, + aInternalName, + aFuncName, + i, + nParamCount, + eParamType, + eAsyncType ); + pLegacyFuncCol->insert(pLegacyFuncData); } - else - delete pLib; - return bRet; + return true; #endif } diff --git a/sc/source/filter/starcalc/scflt.cxx b/sc/source/filter/starcalc/scflt.cxx index 7d3a56e77e64..edf6bf72ca74 100644 --- a/sc/source/filter/starcalc/scflt.cxx +++ b/sc/source/filter/starcalc/scflt.cxx @@ -369,14 +369,12 @@ static OUString lcl_MakeOldPageStyleFormatName( sal_uInt16 i ) template < typename T > sal_uLong insert_new( ScCollection* pCollection, SvStream& rStream ) { - T* pData = new (::std::nothrow) T( rStream); + std::unique_ptr<T> pData(new (::std::nothrow) T( rStream)); sal_uLong nError = rStream.GetError(); if (pData) { - if (nError) - delete pData; - else - pCollection->Insert( pData); + if (!nError) + pCollection->Insert( pData.release() ); } else nError = errOutOfMemory; diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx index 5dc09a3d9c66..411f88beb1cb 100644 --- a/sc/source/ui/unoobj/funcuno.cxx +++ b/sc/source/ui/unoobj/funcuno.cxx @@ -45,6 +45,7 @@ #include "dociter.hxx" #include "stringutil.hxx" #include "tokenarray.hxx" +#include <memory> using namespace com::sun::star; @@ -148,12 +149,12 @@ static bool lcl_CopyData( ScDocument* pSrcDoc, const ScRange& rSrcRange, rSrcRange.aEnd.Row() - rSrcRange.aStart.Row() + rDestPos.Row(), nDestTab ) ); - ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); + std::unique_ptr<ScDocument> pClipDoc(new ScDocument( SCDOCMODE_CLIP )); ScMarkData aSourceMark; aSourceMark.SelectOneTable( nSrcTab ); // for CopyToClip aSourceMark.SetMarkArea( rSrcRange ); ScClipParam aClipParam(rSrcRange, false); - pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aSourceMark); + pSrcDoc->CopyToClip(aClipParam, pClipDoc.get(), &aSourceMark); if ( pClipDoc->HasAttrib( 0,0,nSrcTab, MAXCOL,MAXROW,nSrcTab, HASATTR_MERGED | HASATTR_OVERLAPPED ) ) @@ -167,9 +168,8 @@ static bool lcl_CopyData( ScDocument* pSrcDoc, const ScRange& rSrcRange, ScMarkData aDestMark; aDestMark.SelectOneTable( nDestTab ); aDestMark.SetMarkArea( aNewRange ); - pDestDoc->CopyFromClip( aNewRange, aDestMark, InsertDeleteFlags::ALL & ~InsertDeleteFlags::FORMULA, nullptr, pClipDoc, false ); + pDestDoc->CopyFromClip( aNewRange, aDestMark, InsertDeleteFlags::ALL & ~InsertDeleteFlags::FORMULA, nullptr, pClipDoc.get(), false ); - delete pClipDoc; return true; } |