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 )
SbiBuffer::~SbiBuffer()
{
delete[] pBuf;
}
// Reach out the buffer
......@@ -48,8 +47,7 @@ SbiBuffer::~SbiBuffer()
char* SbiBuffer::GetBuffer()
{
char* p = pBuf;
pBuf = nullptr;
char* p = pBuf.release();
pCur = nullptr;
return p;
}
......@@ -88,15 +86,14 @@ bool SbiBuffer::Check( sal_Int32 n )
{
pParser->Error( ERRCODE_BASIC_PROG_TOO_LARGE );
nInc = 0;
delete[] pBuf; pBuf = nullptr;
pBuf.reset();
return false;
}
else
{
if( nSize ) memcpy( p, pBuf, nSize );
delete[] pBuf;
pBuf = p;
pCur = pBuf + nOff;
if( nSize ) memcpy( p, pBuf.get(), nSize );
pBuf.reset(p);
pCur = pBuf.get() + nOff;
nSize = nSize + nn;
}
}
......@@ -111,7 +108,7 @@ void SbiBuffer::Patch( sal_uInt32 off, sal_uInt32 val )
{
sal_uInt16 val1 = static_cast<sal_uInt16>( val & 0xFFFF );
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 >> 8 );
*p++ = (char) ( val2 & 0xFF );
......@@ -133,7 +130,7 @@ void SbiBuffer::Chain( sal_uInt32 off )
sal_uInt32 val2 = (nOff >> 16);
do
{
ip = reinterpret_cast<sal_uInt8*>(pBuf) + i;
ip = reinterpret_cast<sal_uInt8*>(pBuf.get()) + i;
sal_uInt8* pTmp = ip;
i = *pTmp++; i |= *pTmp++ << 8; i |= *pTmp++ << 16; i |= *pTmp++ << 24;
......
......@@ -185,7 +185,7 @@ static const TokenTable aTokTable_Basic [] = {
// #i109076
TokenLabelInfo::TokenLabelInfo()
{
m_pTokenCanBeLabelTab = new bool[VBASUPPORT+1];
m_pTokenCanBeLabelTab.reset( new bool[VBASUPPORT+1] );
for( int i = 0 ; i <= VBASUPPORT ; ++i )
{
m_pTokenCanBeLabelTab[i] = false;
......@@ -203,7 +203,6 @@ TokenLabelInfo::TokenLabelInfo()
TokenLabelInfo::~TokenLabelInfo()
{
delete[] m_pTokenCanBeLabelTab;
}
......
......@@ -21,12 +21,13 @@
#define INCLUDED_BASIC_SOURCE_INC_BUFFER_HXX
#include <rtl/ustring.hxx>
#include <memory>
class SbiParser;
class SbiBuffer {
SbiParser* pParser; // for error messages
char* pBuf;
std::unique_ptr<char[]> pBuf;
char* pCur;
sal_uInt32 nOff;
sal_uInt32 nSize;
......
......@@ -47,7 +47,7 @@ namespace o3tl
class SbiStream
{
SvStream* pStrm;
std::unique_ptr<SvStream> pStrm;
sal_uInt64 nExpandOnWriteTo; // during writing access expand the stream to this size
OString aLine;
sal_uInt64 nLine;
......@@ -76,7 +76,7 @@ public:
sal_uInt64 GetLine() const { return nLine; }
void SetExpandOnWriteTo( sal_uInt64 n ) { nExpandOnWriteTo = n; }
void ExpandFile();
SvStream* GetStrm() { return pStrm; }
SvStream* GetStrm() { return pStrm.get(); }
};
class SbiIoSystem
......
......@@ -117,7 +117,7 @@ enum SbiToken {
// #i109076
class TokenLabelInfo
{
bool* m_pTokenCanBeLabelTab;
std::unique_ptr<bool[]> m_pTokenCanBeLabelTab;
public:
TokenLabelInfo();
......
......@@ -135,7 +135,6 @@ SbiStream::SbiStream()
SbiStream::~SbiStream()
{
delete pStrm;
}
// map an SvStream-error to StarBASIC-code
......@@ -492,17 +491,17 @@ SbError SbiStream::Open
if( (nStrmMode & (StreamMode::READ | StreamMode::WRITE)) == (StreamMode::READ | StreamMode::WRITE) )
{
Reference< XStream > xIS = xSFI->openFileReadWrite( aNameStr );
pStrm = new UCBStream( xIS );
pStrm.reset( new UCBStream( xIS ) );
}
else if( nStrmMode & StreamMode::WRITE )
{
Reference< XStream > xIS = xSFI->openFileReadWrite( aNameStr );
pStrm = new UCBStream( xIS );
pStrm.reset( new UCBStream( xIS ) );
}
else //if( nStrmMode & StreamMode::READ )
{
Reference< XInputStream > xIS = xSFI->openFileRead( aNameStr );
pStrm = new UCBStream( xIS );
pStrm.reset( new UCBStream( xIS ) );
}
}
......@@ -514,7 +513,7 @@ SbError SbiStream::Open
if( !pStrm )
{
pStrm = new OslStream( aNameStr, nStrmMode );
pStrm.reset( new OslStream( aNameStr, nStrmMode ) );
}
if( IsAppend() )
{
......@@ -523,8 +522,7 @@ SbError SbiStream::Open
MapError();
if( nError )
{
delete pStrm;
pStrm = nullptr;
pStrm.reset();
}
return nError;
}
......@@ -534,8 +532,7 @@ SbError SbiStream::Close()
if( pStrm )
{
MapError();
delete pStrm;
pStrm = nullptr;
pStrm.reset();
}
nChan = 0;
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