Kaydet (Commit) ad694ef6 authored tarafından Noel Grandin's avatar Noel Grandin

new loplugin: useuniqueptr: basic

Change-Id: I5a9806e8dd79431f14d6861c8f4d65f828398f07
Reviewed-on: https://gerrit.libreoffice.org/33145Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst eea337fa
...@@ -40,7 +40,6 @@ SbiBuffer::SbiBuffer( SbiParser* p, short n ) ...@@ -40,7 +40,6 @@ SbiBuffer::SbiBuffer( SbiParser* p, short n )
SbiBuffer::~SbiBuffer() SbiBuffer::~SbiBuffer()
{ {
delete[] pBuf;
} }
// Reach out the buffer // Reach out the buffer
...@@ -48,8 +47,7 @@ SbiBuffer::~SbiBuffer() ...@@ -48,8 +47,7 @@ SbiBuffer::~SbiBuffer()
char* SbiBuffer::GetBuffer() char* SbiBuffer::GetBuffer()
{ {
char* p = pBuf; char* p = pBuf.release();
pBuf = nullptr;
pCur = nullptr; pCur = nullptr;
return p; return p;
} }
...@@ -88,15 +86,14 @@ bool SbiBuffer::Check( sal_Int32 n ) ...@@ -88,15 +86,14 @@ bool SbiBuffer::Check( sal_Int32 n )
{ {
pParser->Error( ERRCODE_BASIC_PROG_TOO_LARGE ); pParser->Error( ERRCODE_BASIC_PROG_TOO_LARGE );
nInc = 0; nInc = 0;
delete[] pBuf; pBuf = nullptr; pBuf.reset();
return false; return false;
} }
else else
{ {
if( nSize ) memcpy( p, pBuf, nSize ); if( nSize ) memcpy( p, pBuf.get(), nSize );
delete[] pBuf; pBuf.reset(p);
pBuf = p; pCur = pBuf.get() + nOff;
pCur = pBuf + nOff;
nSize = nSize + nn; nSize = nSize + nn;
} }
} }
...@@ -111,7 +108,7 @@ void SbiBuffer::Patch( sal_uInt32 off, sal_uInt32 val ) ...@@ -111,7 +108,7 @@ void SbiBuffer::Patch( sal_uInt32 off, sal_uInt32 val )
{ {
sal_uInt16 val1 = static_cast<sal_uInt16>( val & 0xFFFF ); sal_uInt16 val1 = static_cast<sal_uInt16>( val & 0xFFFF );
sal_uInt16 val2 = static_cast<sal_uInt16>( val >> 16 ); sal_uInt16 val2 = static_cast<sal_uInt16>( val >> 16 );
sal_uInt8* p = reinterpret_cast<sal_uInt8*>(pBuf) + off; sal_uInt8* p = reinterpret_cast<sal_uInt8*>(pBuf.get()) + off;
*p++ = (char) ( val1 & 0xFF ); *p++ = (char) ( val1 & 0xFF );
*p++ = (char) ( val1 >> 8 ); *p++ = (char) ( val1 >> 8 );
*p++ = (char) ( val2 & 0xFF ); *p++ = (char) ( val2 & 0xFF );
...@@ -133,7 +130,7 @@ void SbiBuffer::Chain( sal_uInt32 off ) ...@@ -133,7 +130,7 @@ void SbiBuffer::Chain( sal_uInt32 off )
sal_uInt32 val2 = (nOff >> 16); sal_uInt32 val2 = (nOff >> 16);
do do
{ {
ip = reinterpret_cast<sal_uInt8*>(pBuf) + i; ip = reinterpret_cast<sal_uInt8*>(pBuf.get()) + i;
sal_uInt8* pTmp = ip; sal_uInt8* pTmp = ip;
i = *pTmp++; i |= *pTmp++ << 8; i |= *pTmp++ << 16; i |= *pTmp++ << 24; i = *pTmp++; i |= *pTmp++ << 8; i |= *pTmp++ << 16; i |= *pTmp++ << 24;
......
...@@ -185,7 +185,7 @@ static const TokenTable aTokTable_Basic [] = { ...@@ -185,7 +185,7 @@ static const TokenTable aTokTable_Basic [] = {
// #i109076 // #i109076
TokenLabelInfo::TokenLabelInfo() TokenLabelInfo::TokenLabelInfo()
{ {
m_pTokenCanBeLabelTab = new bool[VBASUPPORT+1]; m_pTokenCanBeLabelTab.reset( new bool[VBASUPPORT+1] );
for( int i = 0 ; i <= VBASUPPORT ; ++i ) for( int i = 0 ; i <= VBASUPPORT ; ++i )
{ {
m_pTokenCanBeLabelTab[i] = false; m_pTokenCanBeLabelTab[i] = false;
...@@ -203,7 +203,6 @@ TokenLabelInfo::TokenLabelInfo() ...@@ -203,7 +203,6 @@ TokenLabelInfo::TokenLabelInfo()
TokenLabelInfo::~TokenLabelInfo() TokenLabelInfo::~TokenLabelInfo()
{ {
delete[] m_pTokenCanBeLabelTab;
} }
......
...@@ -21,12 +21,13 @@ ...@@ -21,12 +21,13 @@
#define INCLUDED_BASIC_SOURCE_INC_BUFFER_HXX #define INCLUDED_BASIC_SOURCE_INC_BUFFER_HXX
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <memory>
class SbiParser; class SbiParser;
class SbiBuffer { class SbiBuffer {
SbiParser* pParser; // for error messages SbiParser* pParser; // for error messages
char* pBuf; std::unique_ptr<char[]> pBuf;
char* pCur; char* pCur;
sal_uInt32 nOff; sal_uInt32 nOff;
sal_uInt32 nSize; sal_uInt32 nSize;
......
...@@ -47,7 +47,7 @@ namespace o3tl ...@@ -47,7 +47,7 @@ namespace o3tl
class SbiStream class SbiStream
{ {
SvStream* pStrm; std::unique_ptr<SvStream> pStrm;
sal_uInt64 nExpandOnWriteTo; // during writing access expand the stream to this size sal_uInt64 nExpandOnWriteTo; // during writing access expand the stream to this size
OString aLine; OString aLine;
sal_uInt64 nLine; sal_uInt64 nLine;
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
sal_uInt64 GetLine() const { return nLine; } sal_uInt64 GetLine() const { return nLine; }
void SetExpandOnWriteTo( sal_uInt64 n ) { nExpandOnWriteTo = n; } void SetExpandOnWriteTo( sal_uInt64 n ) { nExpandOnWriteTo = n; }
void ExpandFile(); void ExpandFile();
SvStream* GetStrm() { return pStrm; } SvStream* GetStrm() { return pStrm.get(); }
}; };
class SbiIoSystem class SbiIoSystem
......
...@@ -117,7 +117,7 @@ enum SbiToken { ...@@ -117,7 +117,7 @@ enum SbiToken {
// #i109076 // #i109076
class TokenLabelInfo class TokenLabelInfo
{ {
bool* m_pTokenCanBeLabelTab; std::unique_ptr<bool[]> m_pTokenCanBeLabelTab;
public: public:
TokenLabelInfo(); TokenLabelInfo();
......
...@@ -135,7 +135,6 @@ SbiStream::SbiStream() ...@@ -135,7 +135,6 @@ SbiStream::SbiStream()
SbiStream::~SbiStream() SbiStream::~SbiStream()
{ {
delete pStrm;
} }
// map an SvStream-error to StarBASIC-code // map an SvStream-error to StarBASIC-code
...@@ -492,17 +491,17 @@ SbError SbiStream::Open ...@@ -492,17 +491,17 @@ SbError SbiStream::Open
if( (nStrmMode & (StreamMode::READ | StreamMode::WRITE)) == (StreamMode::READ | StreamMode::WRITE) ) if( (nStrmMode & (StreamMode::READ | StreamMode::WRITE)) == (StreamMode::READ | StreamMode::WRITE) )
{ {
Reference< XStream > xIS = xSFI->openFileReadWrite( aNameStr ); Reference< XStream > xIS = xSFI->openFileReadWrite( aNameStr );
pStrm = new UCBStream( xIS ); pStrm.reset( new UCBStream( xIS ) );
} }
else if( nStrmMode & StreamMode::WRITE ) else if( nStrmMode & StreamMode::WRITE )
{ {
Reference< XStream > xIS = xSFI->openFileReadWrite( aNameStr ); Reference< XStream > xIS = xSFI->openFileReadWrite( aNameStr );
pStrm = new UCBStream( xIS ); pStrm.reset( new UCBStream( xIS ) );
} }
else //if( nStrmMode & StreamMode::READ ) else //if( nStrmMode & StreamMode::READ )
{ {
Reference< XInputStream > xIS = xSFI->openFileRead( aNameStr ); Reference< XInputStream > xIS = xSFI->openFileRead( aNameStr );
pStrm = new UCBStream( xIS ); pStrm.reset( new UCBStream( xIS ) );
} }
} }
...@@ -514,7 +513,7 @@ SbError SbiStream::Open ...@@ -514,7 +513,7 @@ SbError SbiStream::Open
if( !pStrm ) if( !pStrm )
{ {
pStrm = new OslStream( aNameStr, nStrmMode ); pStrm.reset( new OslStream( aNameStr, nStrmMode ) );
} }
if( IsAppend() ) if( IsAppend() )
{ {
...@@ -523,8 +522,7 @@ SbError SbiStream::Open ...@@ -523,8 +522,7 @@ SbError SbiStream::Open
MapError(); MapError();
if( nError ) if( nError )
{ {
delete pStrm; pStrm.reset();
pStrm = nullptr;
} }
return nError; return nError;
} }
...@@ -534,8 +532,7 @@ SbError SbiStream::Close() ...@@ -534,8 +532,7 @@ SbError SbiStream::Close()
if( pStrm ) if( pStrm )
{ {
MapError(); MapError();
delete pStrm; pStrm.reset();
pStrm = nullptr;
} }
nChan = 0; nChan = 0;
return nError; return nError;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment