Skip to content

Commit bf92650

Browse files
rouaultnyalldawson
authored andcommittedMay 29, 2020
Address cppcheck warnings about operatorEqToSelf
1 parent b8b40f6 commit bf92650

File tree

5 files changed

+43
-28
lines changed

5 files changed

+43
-28
lines changed
 

‎src/analysis/raster/qgsrastermatrix.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ QgsRasterMatrix::~QgsRasterMatrix()
4040

4141
QgsRasterMatrix &QgsRasterMatrix::operator=( const QgsRasterMatrix &m )
4242
{
43-
delete[] mData;
44-
mColumns = m.nColumns();
45-
mRows = m.nRows();
46-
int nEntries = mColumns * mRows;
47-
mData = new double[nEntries];
48-
memcpy( mData, m.mData, sizeof( double ) * nEntries );
49-
mNodataValue = m.nodataValue();
43+
if ( this != &m )
44+
{
45+
delete[] mData;
46+
mColumns = m.nColumns();
47+
mRows = m.nRows();
48+
int nEntries = mColumns * mRows;
49+
mData = new double[nEntries];
50+
memcpy( mData, m.mData, sizeof( double ) * nEntries );
51+
mNodataValue = m.nodataValue();
52+
}
5053
return *this;
5154
}
5255

‎src/core/expression/qgsexpression.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,16 @@ QgsExpression::QgsExpression( const QgsExpression &other )
159159

160160
QgsExpression &QgsExpression::operator=( const QgsExpression &other )
161161
{
162-
if ( !d->ref.deref() )
162+
if ( this != &other )
163163
{
164-
delete d;
165-
}
164+
if ( !d->ref.deref() )
165+
{
166+
delete d;
167+
}
166168

167-
d = other.d;
168-
d->ref.ref();
169+
d = other.d;
170+
d->ref.ref();
171+
}
169172
return *this;
170173
}
171174

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,17 @@ QgsGeometry::QgsGeometry( const QgsGeometry &other )
8989

9090
QgsGeometry &QgsGeometry::operator=( QgsGeometry const &other )
9191
{
92-
if ( !d->ref.deref() )
92+
if ( this != &other )
9393
{
94-
delete d;
95-
}
94+
if ( !d->ref.deref() )
95+
{
96+
delete d;
97+
}
9698

97-
mLastError = other.mLastError;
98-
d = other.d;
99-
d->ref.ref();
99+
mLastError = other.mLastError;
100+
d = other.d;
101+
d->ref.ref();
102+
}
100103
return *this;
101104
}
102105

‎src/core/qgspropertytransformer.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,15 @@ QgsCurveTransform::QgsCurveTransform( const QgsCurveTransform &other )
689689

690690
QgsCurveTransform &QgsCurveTransform::operator=( const QgsCurveTransform &other )
691691
{
692-
mControlPoints = other.mControlPoints;
693-
if ( other.mSecondDerivativeArray )
692+
if ( this != &other )
694693
{
695-
delete [] mSecondDerivativeArray;
696-
mSecondDerivativeArray = new double[ mControlPoints.count()];
697-
memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray, sizeof( double ) * mControlPoints.count() );
694+
mControlPoints = other.mControlPoints;
695+
if ( other.mSecondDerivativeArray )
696+
{
697+
delete [] mSecondDerivativeArray;
698+
mSecondDerivativeArray = new double[ mControlPoints.count()];
699+
memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray, sizeof( double ) * mControlPoints.count() );
700+
}
698701
}
699702
return *this;
700703
}

‎src/core/qgsspatialindexkdbush.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ QgsSpatialIndexKDBush::QgsSpatialIndexKDBush( const QgsSpatialIndexKDBush &other
4040

4141
QgsSpatialIndexKDBush &QgsSpatialIndexKDBush::operator=( const QgsSpatialIndexKDBush &other )
4242
{
43-
if ( !d->ref.deref() )
43+
if ( this != &other )
4444
{
45-
delete d;
46-
}
45+
if ( !d->ref.deref() )
46+
{
47+
delete d;
48+
}
4749

48-
d = other.d;
49-
d->ref.ref();
50+
d = other.d;
51+
d->ref.ref();
52+
}
5053
return *this;
5154
}
5255

0 commit comments

Comments
 (0)
Please sign in to comment.