summaryrefslogtreecommitdiff
path: root/hwpfilter
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-04-06 09:46:06 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-04-06 09:22:46 +0000
commitaa09b0c27a6d925da428d6267daadc7338829869 (patch)
treeb0fa576ff64820061d9fb876bebacd23e58ddc56 /hwpfilter
parent0c82dff153d92150729815b919854a9a350aa031 (diff)
loplugin:useuniqueptr extend to catch more localvar cases
i.e. where the code looks like { foo * p = new foo; ... delete p; return ...; } Change-Id: Id5f2e55d0363fc62c72535a23faeaaf1f0ac6aee Reviewed-on: https://gerrit.libreoffice.org/36190 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'hwpfilter')
-rw-r--r--hwpfilter/source/hwpfile.cxx9
-rw-r--r--hwpfilter/source/solver.cxx53
2 files changed, 25 insertions, 37 deletions
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index 90fdfdbfe86c..3ab2b0087a6c 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -244,7 +244,7 @@ void HWPFile::ParaListRead()
bool HWPFile::ReadParaList(std::list < HWPPara* > &aplist, unsigned char flag)
{
- HWPPara *spNode = new HWPPara;
+ std::unique_ptr<HWPPara> spNode( new HWPPara );
unsigned char tmp_etcflag;
unsigned char prev_etcflag = 0;
while (spNode->Read(*this, flag))
@@ -269,11 +269,10 @@ bool HWPFile::ReadParaList(std::list < HWPPara* > &aplist, unsigned char flag)
AddParaShape( &spNode->pshape );
if (!aplist.empty())
- aplist.back()->SetNext(spNode);
- aplist.push_back(spNode);
- spNode = new HWPPara;
+ aplist.back()->SetNext(spNode.get());
+ aplist.push_back(spNode.release());
+ spNode.reset( new HWPPara );
}
- delete spNode;
return true;
}
diff --git a/hwpfilter/source/solver.cxx b/hwpfilter/source/solver.cxx
index 144e11c3858a..f297160159f1 100644
--- a/hwpfilter/source/solver.cxx
+++ b/hwpfilter/source/solver.cxx
@@ -18,6 +18,7 @@
*/
#include <math.h>
+#include <memory>
#include "solver.h"
@@ -63,18 +64,15 @@ double* mgcLinearSystemD::NewVector (int N)
int mgcLinearSystemD::Solve (int n, double** a, double* b)
{
- int* indxc = new int[n];
+ std::unique_ptr<int[]> indxc( new int[n] );
if ( !indxc )
return 0;
- int* indxr = new int[n];
+ std::unique_ptr<int[]> indxr( new int[n] );
if ( !indxr ) {
- delete[] indxc;
return 0;
}
- int* ipiv = new int[n];
+ std::unique_ptr<int[]> ipiv( new int[n] );
if ( !ipiv ) {
- delete[] indxc;
- delete[] indxr;
return 0;
}
@@ -93,26 +91,23 @@ int mgcLinearSystemD::Solve (int n, double** a, double* b)
{
if ( ipiv[j] != 1 )
{
- for (k = 0; k < n; k++)
- {
- if ( ipiv[k] == 0 )
- {
- if ( fabs(a[j][k]) >= big )
+ for (k = 0; k < n; k++)
{
- big = fabs(a[j][k]);
- irow = j;
- icol = k;
+ if ( ipiv[k] == 0 )
+ {
+ if ( fabs(a[j][k]) >= big )
+ {
+ big = fabs(a[j][k]);
+ irow = j;
+ icol = k;
+ }
+ }
+ else if ( ipiv[k] > 1 )
+ {
+ return 0;
+ }
}
}
- else if ( ipiv[k] > 1 )
- {
- delete[] ipiv;
- delete[] indxr;
- delete[] indxc;
- return 0;
- }
- }
- }
}
ipiv[icol]++;
@@ -131,9 +126,6 @@ int mgcLinearSystemD::Solve (int n, double** a, double* b)
indxc[i] = icol;
if ( a[icol][icol] == 0 )
{
- delete[] ipiv;
- delete[] indxr;
- delete[] indxc;
return 0;
}
@@ -162,16 +154,13 @@ int mgcLinearSystemD::Solve (int n, double** a, double* b)
{
for (k = 0; k < n; k++)
{
- save = a[k][indxr[j]];
- a[k][indxr[j]] = a[k][indxc[j]];
- a[k][indxc[j]] = save;
+ save = a[k][indxr[j]];
+ a[k][indxr[j]] = a[k][indxc[j]];
+ a[k][indxc[j]] = save;
}
}
}
- delete[] ipiv;
- delete[] indxr;
- delete[] indxc;
return 1;
}