Skip to content

Commit

Permalink
Address cppcheck warnings about operatorEqToSelf
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault authored and nyalldawson committed May 29, 2020
1 parent b8b40f6 commit bf92650
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
17 changes: 10 additions & 7 deletions src/analysis/raster/qgsrastermatrix.cpp
Expand Up @@ -40,13 +40,16 @@ QgsRasterMatrix::~QgsRasterMatrix()

QgsRasterMatrix &QgsRasterMatrix::operator=( const QgsRasterMatrix &m )
{
delete[] mData;
mColumns = m.nColumns();
mRows = m.nRows();
int nEntries = mColumns * mRows;
mData = new double[nEntries];
memcpy( mData, m.mData, sizeof( double ) * nEntries );
mNodataValue = m.nodataValue();
if ( this != &m )
{
delete[] mData;
mColumns = m.nColumns();
mRows = m.nRows();
int nEntries = mColumns * mRows;
mData = new double[nEntries];
memcpy( mData, m.mData, sizeof( double ) * nEntries );
mNodataValue = m.nodataValue();
}
return *this;
}

Expand Down
13 changes: 8 additions & 5 deletions src/core/expression/qgsexpression.cpp
Expand Up @@ -159,13 +159,16 @@ QgsExpression::QgsExpression( const QgsExpression &other )

QgsExpression &QgsExpression::operator=( const QgsExpression &other )
{
if ( !d->ref.deref() )
if ( this != &other )
{
delete d;
}
if ( !d->ref.deref() )
{
delete d;
}

d = other.d;
d->ref.ref();
d = other.d;
d->ref.ref();
}
return *this;
}

Expand Down
15 changes: 9 additions & 6 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -89,14 +89,17 @@ QgsGeometry::QgsGeometry( const QgsGeometry &other )

QgsGeometry &QgsGeometry::operator=( QgsGeometry const &other )
{
if ( !d->ref.deref() )
if ( this != &other )
{
delete d;
}
if ( !d->ref.deref() )
{
delete d;
}

mLastError = other.mLastError;
d = other.d;
d->ref.ref();
mLastError = other.mLastError;
d = other.d;
d->ref.ref();
}
return *this;
}

Expand Down
13 changes: 8 additions & 5 deletions src/core/qgspropertytransformer.cpp
Expand Up @@ -689,12 +689,15 @@ QgsCurveTransform::QgsCurveTransform( const QgsCurveTransform &other )

QgsCurveTransform &QgsCurveTransform::operator=( const QgsCurveTransform &other )
{
mControlPoints = other.mControlPoints;
if ( other.mSecondDerivativeArray )
if ( this != &other )
{
delete [] mSecondDerivativeArray;
mSecondDerivativeArray = new double[ mControlPoints.count()];
memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray, sizeof( double ) * mControlPoints.count() );
mControlPoints = other.mControlPoints;
if ( other.mSecondDerivativeArray )
{
delete [] mSecondDerivativeArray;
mSecondDerivativeArray = new double[ mControlPoints.count()];
memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray, sizeof( double ) * mControlPoints.count() );
}
}
return *this;
}
Expand Down
13 changes: 8 additions & 5 deletions src/core/qgsspatialindexkdbush.cpp
Expand Up @@ -40,13 +40,16 @@ QgsSpatialIndexKDBush::QgsSpatialIndexKDBush( const QgsSpatialIndexKDBush &other

QgsSpatialIndexKDBush &QgsSpatialIndexKDBush::operator=( const QgsSpatialIndexKDBush &other )
{
if ( !d->ref.deref() )
if ( this != &other )
{
delete d;
}
if ( !d->ref.deref() )
{
delete d;
}

d = other.d;
d->ref.ref();
d = other.d;
d->ref.ref();
}
return *this;
}

Expand Down

0 comments on commit bf92650

Please sign in to comment.