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 /basic | |
parent | Replace several for_each by range based fors and functors by lambdas in sw. (diff) | |
download | core-db17d3c17c40d6b0e92392cf3c6e343d1d17b771.tar.gz core-db17d3c17c40d6b0e92392cf3c6e343d1d17b771.zip |
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 'basic')
-rw-r--r-- | basic/source/runtime/methods.cxx | 13 | ||||
-rw-r--r-- | basic/source/sbx/sbxstr.cxx | 9 |
2 files changed, 11 insertions, 11 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 07e37f2bb6b5..aad84105a293 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -3718,10 +3718,10 @@ RTLFUNC(Shell) ++iter; sal_uInt16 nParamCount = sal::static_int_cast< sal_uInt16 >(aTokenList.size() - 1 ); - rtl_uString** pParamList = nullptr; + std::unique_ptr<rtl_uString*[]> pParamList; if( nParamCount ) { - pParamList = new rtl_uString*[nParamCount]; + pParamList.reset( new rtl_uString*[nParamCount]); for(int iList = 0; iter != aTokenList.end(); ++iList, ++iter) { const OUString& rParamStr = (*iter); @@ -3734,7 +3734,7 @@ RTLFUNC(Shell) oslProcess pApp; bool bSucc = osl_executeProcess( aOUStrProgURL.pData, - pParamList, + pParamList.get(), nParamCount, nOptions, nullptr, @@ -3753,8 +3753,6 @@ RTLFUNC(Shell) rtl_uString_release(pParamList[j]); } - delete [] pParamList; - if( !bSucc ) { StarBASIC::Error( ERRCODE_BASIC_FILE_NOT_FOUND ); @@ -4352,7 +4350,7 @@ RTLFUNC(StrConv) // convert the string to byte string, preserving unicode (2 bytes per character) sal_Int32 nSize = aNewStr.getLength()*2; const sal_Unicode* pSrc = aNewStr.getStr(); - sal_Char* pChar = new sal_Char[nSize+1]; + std::unique_ptr<sal_Char[]> pChar(new sal_Char[nSize+1]); for( sal_Int32 i=0; i < nSize; i++ ) { pChar[i] = static_cast< sal_Char >( (i%2) ? ((*pSrc) >> 8) & 0xff : (*pSrc) & 0xff ); @@ -4362,8 +4360,7 @@ RTLFUNC(StrConv) } } pChar[nSize] = '\0'; - OString aOStr(pChar); - delete[] pChar; + OString aOStr(pChar.get()); // there is no concept about default codepage in unix. so it is incorrectly in unix OUString aOUStr = OStringToOUString(aOStr, osl_getThreadTextEncoding()); diff --git a/basic/source/sbx/sbxstr.cxx b/basic/source/sbx/sbxstr.cxx index f66680b82f4c..71dffbf73df7 100644 --- a/basic/source/sbx/sbxstr.cxx +++ b/basic/source/sbx/sbxstr.cxx @@ -25,6 +25,7 @@ #include "sbxres.hxx" #include "runtime.hxx" #include <rtl/ustrbuf.hxx> +#include <memory> // The conversion of an item onto String was handled via the Put-Methods // of the several data types to avoid duplicated code. @@ -161,10 +162,13 @@ void ImpPutString( SbxValues* p, const OUString* n ) { SbxValues aTmp; aTmp.eType = SbxSTRING; - OUString* pTmp = nullptr; + std::unique_ptr<OUString> pTmp; // as a precaution, if a NULL-Ptr appears if( !n ) - n = pTmp = new OUString; + { + pTmp.reset(new OUString); + n = pTmp.get(); + } aTmp.pOUString = const_cast<OUString*>(n); switch( +p->eType ) { @@ -252,7 +256,6 @@ void ImpPutString( SbxValues* p, const OUString* n ) default: SbxBase::SetError( ERRCODE_SBX_CONVERSION ); } - delete pTmp; } |