1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-02-07 06:30:11 +00:00

Safer copy constructor and copy assignment operator for Gnss_Satellite

Fix clang-tidy bugprone-exception-escape warnings
This commit is contained in:
Carles Fernandez 2024-12-29 22:38:55 +01:00
parent a48e0fee23
commit 6757adf8d5
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D

View File

@ -78,11 +78,22 @@ bool operator==(const Gnss_Satellite& sat1, const Gnss_Satellite& sat2)
// Copy constructor
Gnss_Satellite::Gnss_Satellite(const Gnss_Satellite& other) noexcept
: system(other.system),
block(other.block),
PRN(other.PRN),
: PRN(other.PRN),
rf_link(other.rf_link)
{
try
{
system = other.system;
block = other.block;
}
catch (...)
{
// Handle failure by creating a valid but empty object
system.clear();
block.clear();
PRN = 0;
rf_link = 0;
}
}
@ -92,10 +103,22 @@ Gnss_Satellite& Gnss_Satellite::operator=(const Gnss_Satellite& rhs) noexcept
// Only do assignment if RHS is a different object from this.
if (this != &rhs)
{
this->system = rhs.system;
this->block = rhs.block;
this->PRN = rhs.PRN;
this->rf_link = rhs.rf_link;
try
{
// Copy strings first
std::string tmp_system = rhs.system;
std::string tmp_block = rhs.block;
// If we get here, string copies succeeded
system = std::move(tmp_system);
block = std::move(tmp_block);
PRN = rhs.PRN;
rf_link = rhs.rf_link;
}
catch (...)
{
// Keep object in valid state by not modifying it
}
}
return *this;
}