From 513ac8eb79e45de332d7ddab5b27c70578b904f1 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 26 Jun 2017 09:41:14 +0200 Subject: loplugin:useuniqueptr in various extending it to find places we can use std::unique_ptr on arrays Change-Id: I9feb1d12d738d6931e752ecb6dd51cbc1540c81b Reviewed-on: https://gerrit.libreoffice.org/39255 Tested-by: Jenkins Reviewed-by: Noel Grandin --- xmlhelp/source/cxxhelp/provider/databases.cxx | 27 +++++++++------------------ xmlhelp/source/cxxhelp/provider/databases.hxx | 3 +-- 2 files changed, 10 insertions(+), 20 deletions(-) (limited to 'xmlhelp') diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx index 407a9bd0c9b4..3fc71e0f87c1 100644 --- a/xmlhelp/source/cxxhelp/provider/databases.cxx +++ b/xmlhelp/source/cxxhelp/provider/databases.cxx @@ -127,8 +127,6 @@ Databases::Databases( bool showBasic, Reference< uno::XComponentContext > const & xContext ) : m_xContext( xContext ), m_bShowBasic(showBasic), - m_nCustomCSSDocLength( 0 ), - m_pCustomCSSDoc( nullptr ), m_aCSS(styleSheet.toAsciiLowerCase()), newProdName( "$[officename]" ), newProdVersion( "$[officeversion]" ), @@ -161,10 +159,6 @@ Databases::Databases( bool showBasic, Databases::~Databases() { - // release stylesheet - - delete[] m_pCustomCSSDoc; - // unload the databases { @@ -945,15 +939,13 @@ Reference< XHierarchicalNameAccess > Databases::findJarFileForPath void Databases::changeCSS(const OUString& newStyleSheet) { m_aCSS = newStyleSheet.toAsciiLowerCase(); - delete[] m_pCustomCSSDoc; - m_pCustomCSSDoc = nullptr; - m_nCustomCSSDocLength = 0; + m_vCustomCSSDoc.clear(); } void Databases::cascadingStylesheet( const OUString& Language, OStringBuffer& buffer ) { - if( ! m_pCustomCSSDoc ) + if( m_vCustomCSSDoc.empty() ) { int retry = 2; bool error = true; @@ -1028,11 +1020,10 @@ void Databases::cascadingStylesheet( const OUString& Language, { sal_uInt64 nSize; aFile.getSize( nSize ); - m_nCustomCSSDocLength = (int)nSize; - m_pCustomCSSDoc = new char[ 1 + m_nCustomCSSDocLength ]; - m_pCustomCSSDoc[ m_nCustomCSSDocLength ] = 0; - sal_uInt64 a = m_nCustomCSSDocLength,b = m_nCustomCSSDocLength; - aFile.read( m_pCustomCSSDoc,a,b ); + m_vCustomCSSDoc.resize( nSize + 1); + m_vCustomCSSDoc[nSize] = 0; + sal_uInt64 a = nSize,b = nSize; + aFile.read( m_vCustomCSSDoc.data(), a, b ); aFile.close(); error = false; } @@ -1049,12 +1040,12 @@ void Databases::cascadingStylesheet( const OUString& Language, if( error ) { - m_nCustomCSSDocLength = 0; - m_pCustomCSSDoc = new char[ 1 ]; // Initialize with 1 to avoid gcc compiler warning + m_vCustomCSSDoc.clear(); } } - buffer.append( m_pCustomCSSDoc, m_nCustomCSSDocLength ); + if (!m_vCustomCSSDoc.empty()) + buffer.append( m_vCustomCSSDoc.data(), m_vCustomCSSDoc.size() - 1 ); } void Databases::setActiveText( const OUString& Module, diff --git a/xmlhelp/source/cxxhelp/provider/databases.hxx b/xmlhelp/source/cxxhelp/provider/databases.hxx index 032a39d93848..9a6fd0296b49 100644 --- a/xmlhelp/source/cxxhelp/provider/databases.hxx +++ b/xmlhelp/source/cxxhelp/provider/databases.hxx @@ -235,8 +235,7 @@ namespace chelp { bool m_bShowBasic; - int m_nCustomCSSDocLength; - char* m_pCustomCSSDoc; + std::vector m_vCustomCSSDoc; OUString m_aCSS; enum { -- cgit