mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Properly handle self-asignments
This commit is contained in:
parent
2f24bb5462
commit
aba78f3baa
@ -37,21 +37,23 @@ Matrix::Matrix(const Matrix& M)
|
||||
|
||||
Matrix &Matrix::operator=(const Matrix &M)
|
||||
{
|
||||
if (_h != M._h || _w != M._w) {
|
||||
if (!isNull())
|
||||
delete[] _m;
|
||||
if (this != &M) {
|
||||
if (_h != M._h || _w != M._w) {
|
||||
if (!isNull())
|
||||
delete[] _m;
|
||||
|
||||
_h = M._h; _w = M._w;
|
||||
if (isNull())
|
||||
_m = 0;
|
||||
else
|
||||
_m = new double[_h * _w];
|
||||
_h = M._h; _w = M._w;
|
||||
if (isNull())
|
||||
_m = 0;
|
||||
else
|
||||
_m = new double[_h * _w];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < _h; i++)
|
||||
for (size_t j = 0; j < _w; j++)
|
||||
m(i,j) = M.m(i,j);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < _h; i++)
|
||||
for (size_t j = 0; j < _w; j++)
|
||||
m(i,j) = M.m(i,j);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -128,13 +128,15 @@ Projection::~Projection()
|
||||
|
||||
Projection &Projection::operator=(const Projection &p)
|
||||
{
|
||||
delete _ct;
|
||||
if (this != &p) {
|
||||
delete _ct;
|
||||
|
||||
_gcs = p._gcs;
|
||||
_units = p._units;
|
||||
_ct = p._ct ? p._ct->clone() : 0;
|
||||
_geographic = p._geographic;
|
||||
_cs = p._cs;
|
||||
_gcs = p._gcs;
|
||||
_units = p._units;
|
||||
_ct = p._ct ? p._ct->clone() : 0;
|
||||
_geographic = p._geographic;
|
||||
_cs = p._cs;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user