diff options
Diffstat (limited to 'tools/source/generic/config.cxx')
-rw-r--r-- | tools/source/generic/config.cxx | 36 |
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; |