Add check for self-assignment

This commit is contained in:
jgromes 2024-05-26 09:25:13 +02:00
parent a5e2e58c36
commit 9a9e04d047
3 changed files with 24 additions and 18 deletions

View file

@ -214,6 +214,7 @@ AX25Client::AX25Client(const AX25Client& ax25)
} }
AX25Client& AX25Client::operator=(const AX25Client& ax25) { AX25Client& AX25Client::operator=(const AX25Client& ax25) {
if(&ax25 != this) {
this->phyLayer = ax25.phyLayer; this->phyLayer = ax25.phyLayer;
this->sourceSSID = ax25.sourceSSID; this->sourceSSID = ax25.sourceSSID;
this->preambleLen = ax25.preambleLen; this->preambleLen = ax25.preambleLen;
@ -224,6 +225,7 @@ AX25Client& AX25Client::operator=(const AX25Client& ax25) {
this->bellModem = new BellClient(ax25.audio); this->bellModem = new BellClient(ax25.audio);
} }
#endif #endif
}
return(*this); return(*this);
} }

View file

@ -22,10 +22,12 @@ ExternalRadio::ExternalRadio(const ExternalRadio& ext) : PhysicalLayer(1, 0) {
} }
ExternalRadio& ExternalRadio::operator=(const ExternalRadio& ext) { ExternalRadio& ExternalRadio::operator=(const ExternalRadio& ext) {
if(&ext != this) {
this->prevFrf = ext.prevFrf; this->prevFrf = ext.prevFrf;
if(ext.mod) { if(ext.mod) {
this->mod = new Module(ext.mod->hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, ext.mod->getGpio()); this->mod = new Module(ext.mod->hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, ext.mod->getGpio());
} }
}
return(*this); return(*this);
} }

View file

@ -30,12 +30,14 @@ ITA2String::ITA2String(const ITA2String& ita2) {
} }
ITA2String& ITA2String::operator=(const ITA2String& ita2) { ITA2String& ITA2String::operator=(const ITA2String& ita2) {
if(&ita2 != this) {
this->asciiLen = ita2.asciiLen; this->asciiLen = ita2.asciiLen;
this->ita2Len = ita2.ita2Len; this->ita2Len = ita2.ita2Len;
#if !RADIOLIB_STATIC_ONLY #if !RADIOLIB_STATIC_ONLY
this->strAscii = new char[asciiLen + 1]; this->strAscii = new char[asciiLen + 1];
#endif #endif
strcpy(this->strAscii, ita2.strAscii); strcpy(this->strAscii, ita2.strAscii);
}
return(*this); return(*this);
} }