summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
Diffstat (limited to 'basic')
-rw-r--r--basic/source/classes/image.cxx59
-rw-r--r--basic/source/comp/codegen.cxx2
-rw-r--r--basic/source/inc/image.hxx10
3 files changed, 33 insertions, 38 deletions
diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx
index 34a6431c1876..7636a62d419c 100644
--- a/basic/source/classes/image.cxx
+++ b/basic/source/classes/image.cxx
@@ -53,9 +53,9 @@ SbiImage::~SbiImage()
void SbiImage::Clear()
{
mvStringOffsets.clear();
- delete[] pStrings;
- delete[] pCode;
- ReleaseLegacyBuffer();
+ pStrings.reset();
+ pCode.reset();
+ pLegacyPCode.reset();
pStrings = nullptr;
pCode = nullptr;
nFlags = SbiImageFlags::NONE;
@@ -160,18 +160,17 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
}
case FileOffset::PCode:
if( bBadVer ) break;
- pCode = new char[ nLen ];
+ pCode.reset(new char[ nLen ]);
nCodeSize = nLen;
- r.ReadBytes(pCode, nCodeSize);
+ r.ReadBytes(pCode.get(), nCodeSize);
if ( bLegacy )
{
- ReleaseLegacyBuffer(); // release any previously held buffer
nLegacyCodeSize = static_cast<sal_uInt16>(nCodeSize);
- pLegacyPCode = pCode;
+ pLegacyPCode = std::move(pCode);
- PCodeBuffConvertor< sal_uInt16, sal_uInt32 > aLegacyToNew( reinterpret_cast<sal_uInt8*>(pLegacyPCode), nLegacyCodeSize );
+ PCodeBuffConvertor< sal_uInt16, sal_uInt32 > aLegacyToNew( reinterpret_cast<sal_uInt8*>(pLegacyPCode.get()), nLegacyCodeSize );
aLegacyToNew.convert();
- pCode = reinterpret_cast<char*>(aLegacyToNew.GetBuffer());
+ pCode.reset(reinterpret_cast<char*>(aLegacyToNew.GetBuffer()));
nCodeSize = aLegacyToNew.GetSize();
// we don't release the legacy buffer
// right now, that's because the module
@@ -209,8 +208,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
r.ReadUInt32( nLen );
if( SbiGood( r ) )
{
- delete [] pStrings;
- pStrings = new sal_Unicode[ nLen ];
+ pStrings.reset(new sal_Unicode[ nLen ]);
nStringSize = static_cast<sal_uInt16>(nLen);
std::unique_ptr<char[]> pByteStrings(new char[ nLen ]);
@@ -219,7 +217,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
{
sal_uInt16 nOff2 = static_cast<sal_uInt16>(mvStringOffsets[ j ]);
OUString aStr( pByteStrings.get() + nOff2, strlen(pByteStrings.get() + nOff2), eCharSet );
- memcpy( pStrings + nOff2, aStr.getStr(), (aStr.getLength() + 1) * sizeof( sal_Unicode ) );
+ memcpy( pStrings.get() + nOff2, aStr.getStr(), (aStr.getLength() + 1) * sizeof( sal_Unicode ) );
}
}
break;
@@ -405,16 +403,15 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
nPos = SbiOpenRecord( r, FileOffset::PCode, 1 );
if ( bLegacy )
{
- ReleaseLegacyBuffer(); // release any previously held buffer
- PCodeBuffConvertor< sal_uInt32, sal_uInt16 > aNewToLegacy( reinterpret_cast<sal_uInt8*>(pCode), nCodeSize );
+ PCodeBuffConvertor< sal_uInt32, sal_uInt16 > aNewToLegacy( reinterpret_cast<sal_uInt8*>(pCode.get()), nCodeSize );
aNewToLegacy.convert();
- pLegacyPCode = reinterpret_cast<char*>(aNewToLegacy.GetBuffer());
+ pLegacyPCode.reset(reinterpret_cast<char*>(aNewToLegacy.GetBuffer()));
nLegacyCodeSize = aNewToLegacy.GetSize();
- r.WriteBytes(pLegacyPCode, nLegacyCodeSize);
+ r.WriteBytes(pLegacyPCode.get(), nLegacyCodeSize);
}
else
{
- r.WriteBytes(pCode, nCodeSize);
+ r.WriteBytes(pCode.get(), nCodeSize);
}
SbiCloseRecord( r, nPos );
}
@@ -433,7 +430,7 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
for( size_t i = 0; i < mvStringOffsets.size(); i++ )
{
sal_uInt16 nOff = static_cast<sal_uInt16>(mvStringOffsets[ i ]);
- OString aStr(OUStringToOString(OUString(pStrings + nOff), eCharSet));
+ OString aStr(OUStringToOString(OUString(pStrings.get() + nOff), eCharSet));
memcpy( pByteStrings.get() + nOff, aStr.getStr(), (aStr.getLength() + 1) * sizeof( char ) );
}
r.WriteUInt32( nStringSize );
@@ -534,10 +531,10 @@ void SbiImage::MakeStrings( short nSize )
nStringIdx = 0;
nStringOff = 0;
nStringSize = 1024;
- pStrings = new sal_Unicode[ nStringSize ];
+ pStrings.reset( new sal_Unicode[ nStringSize ]);
mvStringOffsets.resize(nSize);
memset( mvStringOffsets.data(), 0, nSize * sizeof( sal_uInt32 ) );
- memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
+ memset( pStrings.get(), 0, nStringSize * sizeof( sal_Unicode ) );
}
// Add a string to StringPool. The String buffer is dynamically
@@ -560,16 +557,15 @@ void SbiImage::AddString( const OUString& r )
{
sal_uInt32 nNewLen = needed + 1024;
nNewLen &= 0xFFFFFC00; // trim to 1K border
- sal_Unicode* p = new sal_Unicode[nNewLen];
- memcpy( p, pStrings, nStringSize * sizeof( sal_Unicode ) );
- delete[] pStrings;
- pStrings = p;
+ std::unique_ptr<sal_Unicode[]> p(new sal_Unicode[nNewLen]);
+ memcpy( p.get(), pStrings.get(), nStringSize * sizeof( sal_Unicode ) );
+ pStrings = std::move(p);
nStringSize = sal::static_int_cast< sal_uInt16 >(nNewLen);
}
if( !bError )
{
mvStringOffsets[ nStringIdx++ ] = nStringOff;
- memcpy( pStrings + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) );
+ memcpy( pStrings.get() + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) );
nStringOff = nStringOff + len;
// Last String? The update the size of the buffer
if( nStringIdx >= short(mvStringOffsets.size()) )
@@ -584,9 +580,9 @@ void SbiImage::AddString( const OUString& r )
// The block was fetched by the compiler from class SbBuffer and
// is already created with new. Additionally it contains all Integers
// in Big Endian format, so can be directly read/written.
-void SbiImage::AddCode( char* p, sal_uInt32 s )
+void SbiImage::AddCode( std::unique_ptr<char[]> p, sal_uInt32 s )
{
- pCode = p;
+ pCode = std::move(p);
nCodeSize = s;
}
@@ -616,7 +612,7 @@ OUString SbiImage::GetString( short nId ) const
if( nId && nId <= short(mvStringOffsets.size()) )
{
sal_uInt32 nOff = mvStringOffsets[ nId - 1 ];
- sal_Unicode* pStr = pStrings + nOff;
+ sal_Unicode* pStr = pStrings.get() + nOff;
// #i42467: Special treatment for vbNullChar
if( *pStr == 0 )
@@ -645,18 +641,17 @@ const SbxObject* SbiImage::FindType (const OUString& aTypeName) const
sal_uInt16 SbiImage::CalcLegacyOffset( sal_Int32 nOffset )
{
- return SbiCodeGen::calcLegacyOffSet( reinterpret_cast<sal_uInt8*>(pCode), nOffset ) ;
+ return SbiCodeGen::calcLegacyOffSet( reinterpret_cast<sal_uInt8*>(pCode.get()), nOffset ) ;
}
sal_uInt32 SbiImage::CalcNewOffset( sal_Int16 nOffset )
{
- return SbiCodeGen::calcNewOffSet( reinterpret_cast<sal_uInt8*>(pLegacyPCode), nOffset ) ;
+ return SbiCodeGen::calcNewOffSet( reinterpret_cast<sal_uInt8*>(pLegacyPCode.get()), nOffset ) ;
}
void SbiImage::ReleaseLegacyBuffer()
{
- delete[] pLegacyPCode;
- pLegacyPCode = nullptr;
+ pLegacyPCode.reset();
nLegacyCodeSize = 0;
}
diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx
index bcab0d0a0f95..9e38c02a7cb9 100644
--- a/basic/source/comp/codegen.cxx
+++ b/basic/source/comp/codegen.cxx
@@ -350,7 +350,7 @@ void SbiCodeGen::Save()
}
}
// The code
- p->AddCode( aCode.GetBuffer(), aCode.GetSize() );
+ p->AddCode( std::unique_ptr<char[]>(aCode.GetBuffer()), aCode.GetSize() );
// The global StringPool. 0 is not occupied.
SbiStringPool* pPool = &pParser->aGblStrings;
diff --git a/basic/source/inc/image.hxx b/basic/source/inc/image.hxx
index f79e3c51c98a..f286e3e286fb 100644
--- a/basic/source/inc/image.hxx
+++ b/basic/source/inc/image.hxx
@@ -47,9 +47,9 @@ class SbiImage {
SbxArrayRef rTypes; // User defined types
SbxArrayRef rEnums; // Enum types
std::vector<sal_uInt32> mvStringOffsets; // StringId-Offsets
- sal_Unicode* pStrings; // StringPool
- char* pCode; // Code-Image
- char* pLegacyPCode; // Code-Image
+ std::unique_ptr<sal_Unicode[]> pStrings; // StringPool
+ std::unique_ptr<char[]> pCode; // Code-Image
+ std::unique_ptr<char[]> pLegacyPCode; // Code-Image
bool bError;
SbiImageFlags nFlags;
sal_uInt32 nStringSize;
@@ -63,7 +63,7 @@ class SbiImage {
// routines for the compiler:
void MakeStrings( short ); // establish StringPool
void AddString( const OUString& );
- void AddCode( char*, sal_uInt32 );
+ void AddCode( std::unique_ptr<char[]>, sal_uInt32 );
void AddType(SbxObject const *);
void AddEnum(SbxObject *);
@@ -83,7 +83,7 @@ public:
bool Save( SvStream&, sal_uInt32 = B_CURVERSION );
bool IsError() { return bError; }
- const char* GetCode() const { return pCode; }
+ const char* GetCode() const { return pCode.get(); }
sal_uInt32 GetCodeSize() const { return nCodeSize; }
sal_uInt16 GetBase() const { return nDimBase; }
OUString GetString( short nId ) const;