[Libreoffice-commits] core.git: 2 commits - svl/source tools/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Oct 31 06:32:49 UTC 2018
svl/source/items/poolcach.cxx | 6 +++---
tools/source/generic/config.cxx | 36 +++++++++++++++++-------------------
2 files changed, 20 insertions(+), 22 deletions(-)
New commits:
commit c2ce64682155815b433a5a1c380e041caf6c4028
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Oct 29 14:27:18 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Oct 31 07:32:33 2018 +0100
loplugin:useuniqueptr in ImplSysReadConfig
Change-Id: I59fc342e480b6ace1bbe366692d834f1076abac2
Reviewed-on: https://gerrit.libreoffice.org/62653
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
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;
commit c969f04f72b95c5d3a1fdd3cf8190826bab440c2
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Oct 29 14:27:04 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Oct 31 07:32:22 2018 +0100
loplugin:useuniqueptr in SfxItemPoolCache::ApplyTo
Change-Id: Ica6ffb5bbaad5c941c65cae02bba7ea2380646f3
Reviewed-on: https://gerrit.libreoffice.org/62652
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/svl/source/items/poolcach.cxx b/svl/source/items/poolcach.cxx
index c43d1d50973e..f9e29a7879a5 100644
--- a/svl/source/items/poolcach.cxx
+++ b/svl/source/items/poolcach.cxx
@@ -78,7 +78,7 @@ const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem )
}
// Insert the new attributes in a new Set
- SfxSetItem *pNewItem = static_cast<SfxSetItem *>(rOrigItem.Clone());
+ std::unique_ptr<SfxSetItem> pNewItem(static_cast<SfxSetItem *>(rOrigItem.Clone()));
if ( pItemToPut )
{
pNewItem->GetItemSet().PutDirect( *pItemToPut );
@@ -88,8 +88,8 @@ const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem )
else
pNewItem->GetItemSet().Put( *pSetToPut );
const SfxSetItem* pNewPoolItem = static_cast<const SfxSetItem*>(&pPool->Put( *pNewItem ));
- DBG_ASSERT( pNewPoolItem != pNewItem, "Pool: same in and out?" );
- delete pNewItem;
+ DBG_ASSERT( pNewPoolItem != pNewItem.get(), "Pool: same in and out?" );
+ pNewItem.reset();
// Adapt refcount; one each for the cache
pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 );
More information about the Libreoffice-commits
mailing list