summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-10-29 14:27:18 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-31 07:32:33 +0100
commitc2ce64682155815b433a5a1c380e041caf6c4028 (patch)
treeb50a982ef598bc123ee78b2fc2c313eafa840849 /tools
parentc969f04f72b95c5d3a1fdd3cf8190826bab440c2 (diff)
loplugin:useuniqueptr in ImplSysReadConfig
Change-Id: I59fc342e480b6ace1bbe366692d834f1076abac2 Reviewed-on: https://gerrit.libreoffice.org/62653 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools')
-rw-r--r--tools/source/generic/config.cxx36
1 files changed, 17 insertions, 19 deletions
diff --git a/tools/source/generic/config.cxx b/tools/source/generic/config.cxx
index f27542070fb2..7c18f5390677 100644
--- a/tools/source/generic/config.cxx
+++ b/tools/source/generic/config.cxx
@@ -92,10 +92,10 @@ static sal_uInt32 ImplSysGetConfigTimeStamp( const OUString& rFileName )
return nTimeStamp;
}
-static sal_uInt8* ImplSysReadConfig( const OUString& rFileName,
+static std::unique_ptr<sal_uInt8[]> ImplSysReadConfig( const OUString& rFileName,
sal_uInt64& rRead, bool& rbRead, bool& rbIsUTF8BOM, sal_uInt32& rTimeStamp )
{
- sal_uInt8* pBuf = nullptr;
+ std::unique_ptr<sal_uInt8[]> pBuf;
::osl::File aFile( rFileName );
if( aFile.open( osl_File_OpenFlag_Read ) == ::osl::FileBase::E_None )
@@ -107,16 +107,16 @@ static sal_uInt8* ImplSysReadConfig( const OUString& rFileName,
aFile.close();
return nullptr;
}
- pBuf = new sal_uInt8[static_cast< std::size_t >(nPos)];
+ pBuf.reset(new sal_uInt8[static_cast< std::size_t >(nPos)]);
sal_uInt64 nRead = 0;
- if( aFile.read( pBuf, nPos, nRead ) == ::osl::FileBase::E_None && nRead == nPos )
+ if( aFile.read( pBuf.get(), nPos, nRead ) == ::osl::FileBase::E_None && nRead == nPos )
{
//skip the byte-order-mark 0xEF 0xBB 0xBF, if it was UTF8 files
unsigned char const BOM[3] = {0xEF, 0xBB, 0xBF};
- if (nRead > 2 && memcmp(pBuf, BOM, 3) == 0)
+ if (nRead > 2 && memcmp(pBuf.get(), BOM, 3) == 0)
{
nRead -= 3;
- memmove(pBuf, pBuf + 3, sal::static_int_cast<std::size_t>(nRead * sizeof(sal_uInt8)) );
+ memmove(pBuf.get(), pBuf.get() + 3, sal::static_int_cast<std::size_t>(nRead * sizeof(sal_uInt8)) );
rbIsUTF8BOM = true;
}
@@ -126,8 +126,7 @@ static sal_uInt8* ImplSysReadConfig( const OUString& rFileName,
}
else
{
- delete[] pBuf;
- pBuf = nullptr;
+ pBuf.reset();
}
}
aFile.close();
@@ -360,9 +359,9 @@ static void ImplMakeConfigList( ImplConfigData* pData,
}
}
-static sal_uInt8* ImplGetConfigBuffer( const ImplConfigData* pData, sal_uInt32& rLen )
+static std::unique_ptr<sal_uInt8[]> ImplGetConfigBuffer( const ImplConfigData* pData, sal_uInt32& rLen )
{
- sal_uInt8* pWriteBuf;
+ std::unique_ptr<sal_uInt8[]> pWriteBuf;
sal_uInt8* pBuf;
sal_uInt8 aLineEndBuf[2] = {0, 0};
ImplKeyData* pKey;
@@ -409,7 +408,7 @@ static sal_uInt8* ImplGetConfigBuffer( const ImplConfigData* pData, sal_uInt32&
rLen = nBufLen;
if ( !nBufLen )
{
- pWriteBuf = new sal_uInt8[nLineEndLen];
+ pWriteBuf.reset(new sal_uInt8[nLineEndLen]);
pWriteBuf[0] = aLineEndBuf[0];
if ( nLineEndLen == 2 )
pWriteBuf[1] = aLineEndBuf[1];
@@ -417,10 +416,10 @@ static sal_uInt8* ImplGetConfigBuffer( const ImplConfigData* pData, sal_uInt32&
}
// Allocate new write buffer (caller frees it)
- pWriteBuf = new sal_uInt8[nBufLen];
+ pWriteBuf.reset(new sal_uInt8[nBufLen]);
// fill buffer
- pBuf = pWriteBuf;
+ pBuf = pWriteBuf.get();
pGroup = pData->mpFirstGroup;
while ( pGroup )
{
@@ -496,13 +495,13 @@ static void ImplReadConfig( ImplConfigData* pData )
sal_uInt64 nRead = 0;
bool bRead = false;
bool bIsUTF8BOM = false;
- sal_uInt8* pBuf = ImplSysReadConfig( pData->maFileName, nRead, bRead, bIsUTF8BOM, nTimeStamp );
+ std::unique_ptr<sal_uInt8[]> pBuf = ImplSysReadConfig( pData->maFileName, nRead, bRead, bIsUTF8BOM, nTimeStamp );
// Read config list from buffer
if ( pBuf )
{
- ImplMakeConfigList( pData, pBuf, nRead );
- delete[] pBuf;
+ ImplMakeConfigList( pData, pBuf.get(), nRead );
+ pBuf.reset();
}
pData->mnTimeStamp = nTimeStamp;
pData->mbModified = false;
@@ -519,12 +518,11 @@ static void ImplWriteConfig( ImplConfigData* pData )
// Read config list from buffer
sal_uInt32 nBufLen;
- sal_uInt8* pBuf = ImplGetConfigBuffer( pData, nBufLen );
+ std::unique_ptr<sal_uInt8[]> pBuf = ImplGetConfigBuffer( pData, nBufLen );
if ( pBuf )
{
- if ( ImplSysWriteConfig( pData->maFileName, pBuf, nBufLen, pData->mbIsUTF8BOM, pData->mnTimeStamp ) )
+ if ( ImplSysWriteConfig( pData->maFileName, pBuf.get(), nBufLen, pData->mbIsUTF8BOM, pData->mnTimeStamp ) )
pData->mbModified = false;
- delete[] pBuf;
}
else
pData->mbModified = false;