summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-01-16 08:49:29 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-01-16 07:30:09 +0000
commitad694ef65a54746bc8c916c5bbbbde6dc483f7a8 (patch)
tree4ad1bd81a05d5330374b5b7ef315900a6727a6a6 /basic
parenteea337faafeae05bc1dd40e38e327202cebbc3f2 (diff)
new loplugin: useuniqueptr: basic
Change-Id: I5a9806e8dd79431f14d6861c8f4d65f828398f07 Reviewed-on: https://gerrit.libreoffice.org/33145 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basic')
-rw-r--r--basic/source/comp/buffer.cxx17
-rw-r--r--basic/source/comp/token.cxx3
-rw-r--r--basic/source/inc/buffer.hxx3
-rw-r--r--basic/source/inc/iosys.hxx4
-rw-r--r--basic/source/inc/token.hxx2
-rw-r--r--basic/source/runtime/iosys.cxx15
6 files changed, 19 insertions, 25 deletions
diff --git a/basic/source/comp/buffer.cxx b/basic/source/comp/buffer.cxx
index 7d95705b6354..9c1e216fd872 100644
--- a/basic/source/comp/buffer.cxx
+++ b/basic/source/comp/buffer.cxx
@@ -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;
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index f779fc1bef6e..40397d3ee149 100644
--- a/basic/source/comp/token.cxx
+++ b/basic/source/comp/token.cxx
@@ -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;
}
diff --git a/basic/source/inc/buffer.hxx b/basic/source/inc/buffer.hxx
index 3b1b5a8b555e..525a193566c6 100644
--- a/basic/source/inc/buffer.hxx
+++ b/basic/source/inc/buffer.hxx
@@ -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;
diff --git a/basic/source/inc/iosys.hxx b/basic/source/inc/iosys.hxx
index 151bdf11d6b7..9deb4bda4c96 100644
--- a/basic/source/inc/iosys.hxx
+++ b/basic/source/inc/iosys.hxx
@@ -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
diff --git a/basic/source/inc/token.hxx b/basic/source/inc/token.hxx
index e3b3a8a5473b..43f535b8cc0d 100644
--- a/basic/source/inc/token.hxx
+++ b/basic/source/inc/token.hxx
@@ -117,7 +117,7 @@ enum SbiToken {
// #i109076
class TokenLabelInfo
{
- bool* m_pTokenCanBeLabelTab;
+ std::unique_ptr<bool[]> m_pTokenCanBeLabelTab;
public:
TokenLabelInfo();
diff --git a/basic/source/runtime/iosys.cxx b/basic/source/runtime/iosys.cxx
index 12b3dbcbd278..2f816884cfcf 100644
--- a/basic/source/runtime/iosys.cxx
+++ b/basic/source/runtime/iosys.cxx
@@ -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;