extensions/source/scanner/sane.cxx | 8 ++++---- extensions/source/scanner/sane.hxx | 2 +- extensions/source/scanner/sanedlg.cxx | 22 ++++++---------------- extensions/source/scanner/sanedlg.hxx | 2 +- xmlhelp/source/cxxhelp/provider/db.cxx | 20 ++++++++------------ xmlhelp/source/cxxhelp/provider/db.hxx | 7 +++---- 6 files changed, 23 insertions(+), 38 deletions(-)
New commits: commit 858e6b266476e5a18111fce883465e734942a50f Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Tue May 8 10:29:21 2018 +0200 loplugin:useuniqueptr in SaneDlg Change-Id: I712b733c9c24db2e2fcdc4b6ce16e38eaf0b27f0 Reviewed-on: https://gerrit.libreoffice.org/54167 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx index 90eb652282b2..614aaccf8145 100644 --- a/extensions/source/scanner/sane.cxx +++ b/extensions/source/scanner/sane.cxx @@ -888,7 +888,7 @@ bool Sane::Start( BitmapTransporter& rBitmap ) return bSuccess; } -int Sane::GetRange( int n, double*& rpDouble ) +int Sane::GetRange( int n, std::unique_ptr<double[]>& rpDouble ) { if( mppOptions[n]->constraint_type != SANE_CONSTRAINT_RANGE && mppOptions[n]->constraint_type != SANE_CONSTRAINT_WORD_LIST ) @@ -921,7 +921,7 @@ int Sane::GetRange( int n, double*& rpDouble ) dbg_msg( "quantum range [ %lg ; %lg ; %lg ]\n", fMin, fQuant, fMax ); nItems = static_cast<int>((fMax - fMin)/fQuant)+1; - rpDouble = new double[ nItems ]; + rpDouble.reset(new double[ nItems ]); double fValue = fMin; for( i = 0; i < nItems; i++, fValue += fQuant ) rpDouble[i] = fValue; @@ -932,7 +932,7 @@ int Sane::GetRange( int n, double*& rpDouble ) { dbg_msg( "normal range [ %lg %lg ]\n", fMin, fMax ); - rpDouble = new double[2]; + rpDouble.reset(new double[2]); rpDouble[0] = fMin; rpDouble[1] = fMax; return 0; @@ -941,7 +941,7 @@ int Sane::GetRange( int n, double*& rpDouble ) else { nItems = mppOptions[n]->constraint.word_list[0]; - rpDouble = new double[nItems]; + rpDouble.reset(new double[nItems]); for( i=0; i<nItems; i++ ) { rpDouble[i] = bIsFixed ? diff --git a/extensions/source/scanner/sane.hxx b/extensions/source/scanner/sane.hxx index 7145ab133b27..94fe3eb45baa 100644 --- a/extensions/source/scanner/sane.hxx +++ b/extensions/source/scanner/sane.hxx @@ -130,7 +130,7 @@ public: { return mppOptions[n]->constraint_type; } const char** GetStringConstraint( int n ) { return const_cast<const char**>(mppOptions[n]->constraint.string_list); } - int GetRange( int, double*& ); + int GetRange( int, std::unique_ptr<double[]>& ); inline int GetOptionElements( int n ); int GetOptionByName( const char* ); diff --git a/extensions/source/scanner/sanedlg.cxx b/extensions/source/scanner/sanedlg.cxx index f7062a13f283..ff4e7db39e14 100644 --- a/extensions/source/scanner/sanedlg.cxx +++ b/extensions/source/scanner/sanedlg.cxx @@ -396,7 +396,7 @@ void SaneDlg::InitFields() mpReslBox->Enable(); mpReslBox->SetValue( static_cast<long>(fRes) ); - double *pDouble = nullptr; + std::unique_ptr<double[]> pDouble; nValue = mrSane.GetRange( nOption, pDouble ); if( nValue > -1 ) { @@ -434,7 +434,6 @@ void SaneDlg::InitFields() } else mpReslBox->Enable( false ); - delete [] pDouble; } } else @@ -485,7 +484,7 @@ void SaneDlg::InitFields() case 3: aBottomRight.setY( static_cast<int>(fValue) );break; } } - double *pDouble = nullptr; + std::unique_ptr<double[]> pDouble; nValue = mrSane.GetRange( nOption, pDouble ); if( nValue > -1 ) { @@ -513,7 +512,6 @@ void SaneDlg::InitFields() case 3: aMaxBottomRight.setY( static_cast<int>(fValue) );break; } } - delete [] pDouble; pField->Enable(); } else @@ -787,7 +785,7 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void ) int nOption = mrSane.GetOptionByName( "resolution" ); if( nOption != -1 ) { - double* pDouble = nullptr; + std::unique_ptr<double[]> pDouble; int nValues = mrSane.GetRange( nOption, pDouble ); if( nValues > 0 ) { @@ -807,7 +805,6 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void ) if( fRes > pDouble[ 1 ] ) fRes = pDouble[ 1 ]; } - delete[] pDouble; mpReslBox->SetValue( static_cast<sal_uLong>(fRes) ); } } @@ -1021,18 +1018,13 @@ void SaneDlg::EstablishStringRange() void SaneDlg::EstablishQuantumRange() { - if( mpRange ) - { - delete [] mpRange; - mpRange = nullptr; - } + mpRange.reset(); int nValues = mrSane.GetRange( mnCurrentOption, mpRange ); if( nValues == 0 ) { mfMin = mpRange[ 0 ]; mfMax = mpRange[ 1 ]; - delete [] mpRange; - mpRange = nullptr; + mpRange.reset(); EstablishNumericOption(); } else if( nValues > 0 ) @@ -1485,11 +1477,10 @@ bool SaneDlg::SetAdjustedNumericalValue( if( nElement < 0 || nElement >= mrSane.GetOptionElements( nOption ) ) return false; - double* pValues = nullptr; + std::unique_ptr<double[]> pValues; int nValues; if( ( nValues = mrSane.GetRange( nOption, pValues ) ) < 0 ) { - delete [] pValues; return false; } @@ -1516,7 +1507,6 @@ bool SaneDlg::SetAdjustedNumericalValue( if( fValue > pValues[1] ) fValue = pValues[1]; } - delete [] pValues; mrSane.SetOptionValue( nOption, fValue, nElement ); SAL_INFO("extensions.scanner", "yields " << fValue); diff --git a/extensions/source/scanner/sanedlg.hxx b/extensions/source/scanner/sanedlg.hxx index 91dd9843bd1a..87f998a526e9 100644 --- a/extensions/source/scanner/sanedlg.hxx +++ b/extensions/source/scanner/sanedlg.hxx @@ -75,7 +75,7 @@ private: int mnCurrentOption; int mnCurrentElement; - double* mpRange; + std::unique_ptr<double[]> mpRange; double mfMin, mfMax; bool doScan; commit 6a017237e01a25ce6901d1cf85ac0408f8935b11 Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Tue May 8 09:44:04 2018 +0200 loplugin:useuniqueptr in helpdatafileproxy::Hdf Change-Id: I4324a290b826d76f89319f556aededb30d921f8d Reviewed-on: https://gerrit.libreoffice.org/54166 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/xmlhelp/source/cxxhelp/provider/db.cxx b/xmlhelp/source/cxxhelp/provider/db.cxx index 9c3c2fa9fe2a..c99a07403104 100644 --- a/xmlhelp/source/cxxhelp/provider/db.cxx +++ b/xmlhelp/source/cxxhelp/provider/db.cxx @@ -68,13 +68,13 @@ void Hdf::createHashMap( bool bOptimizeForPerformance ) { if( m_pStringToDataMap != nullptr ) return; - m_pStringToDataMap = new StringToDataMap; + m_pStringToDataMap.reset(new StringToDataMap); } else { if( m_pStringToValPosMap != nullptr ) return; - m_pStringToValPosMap = new StringToValPosMap; + m_pStringToValPosMap.reset(new StringToValPosMap); } Reference< XInputStream > xIn = m_xSFA->openFileRead( m_aFileURL ); @@ -123,19 +123,15 @@ void Hdf::createHashMap( bool bOptimizeForPerformance ) void Hdf::releaseHashMap() { - if( m_pStringToDataMap != nullptr ) - { - delete m_pStringToDataMap; - m_pStringToDataMap = nullptr; - } - if( m_pStringToValPosMap != nullptr ) - { - delete m_pStringToValPosMap; - m_pStringToValPosMap = nullptr; - } + m_pStringToDataMap.reset(); + m_pStringToValPosMap.reset(); } +Hdf::~Hdf() +{ +} + bool Hdf::getValueForKey( const OString& rKey, HDFData& rValue ) { bool bSuccess = false; diff --git a/xmlhelp/source/cxxhelp/provider/db.hxx b/xmlhelp/source/cxxhelp/provider/db.hxx index e0d7d60e9c40..b26797c80593 100644 --- a/xmlhelp/source/cxxhelp/provider/db.hxx +++ b/xmlhelp/source/cxxhelp/provider/db.hxx @@ -52,8 +52,8 @@ namespace helpdatafileproxy { class Hdf { OUString m_aFileURL; - StringToDataMap* m_pStringToDataMap; - StringToValPosMap* m_pStringToValPosMap; + std::unique_ptr<StringToDataMap> m_pStringToDataMap; + std::unique_ptr<StringToValPosMap> m_pStringToValPosMap; css::uno::Reference< css::ucb::XSimpleFileAccess3 > m_xSFA; @@ -81,8 +81,7 @@ namespace helpdatafileproxy { { OSL_ASSERT(comphelper::isFileUrl(rFileURL)); } - ~Hdf() - { releaseHashMap(); } + ~Hdf(); void createHashMap( bool bOptimizeForPerformance ); void releaseHashMap(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits