1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00

Properly handle self-asignments

This commit is contained in:
Martin Tůma 2019-07-10 23:08:58 +02:00
parent 2f24bb5462
commit aba78f3baa
2 changed files with 22 additions and 18 deletions

View File

@ -37,6 +37,7 @@ Matrix::Matrix(const Matrix& M)
Matrix &Matrix::operator=(const Matrix &M) Matrix &Matrix::operator=(const Matrix &M)
{ {
if (this != &M) {
if (_h != M._h || _w != M._w) { if (_h != M._h || _w != M._w) {
if (!isNull()) if (!isNull())
delete[] _m; delete[] _m;
@ -51,6 +52,7 @@ Matrix &Matrix::operator=(const Matrix &M)
for (size_t i = 0; i < _h; i++) for (size_t i = 0; i < _h; i++)
for (size_t j = 0; j < _w; j++) for (size_t j = 0; j < _w; j++)
m(i,j) = M.m(i,j); m(i,j) = M.m(i,j);
}
return *this; return *this;
} }

View File

@ -128,6 +128,7 @@ Projection::~Projection()
Projection &Projection::operator=(const Projection &p) Projection &Projection::operator=(const Projection &p)
{ {
if (this != &p) {
delete _ct; delete _ct;
_gcs = p._gcs; _gcs = p._gcs;
@ -135,6 +136,7 @@ Projection &Projection::operator=(const Projection &p)
_ct = p._ct ? p._ct->clone() : 0; _ct = p._ct ? p._ct->clone() : 0;
_geographic = p._geographic; _geographic = p._geographic;
_cs = p._cs; _cs = p._cs;
}
return *this; return *this;
} }