QHostInfo: simplify assignment operator

The d_ptr is never nullptr. If it could be, then other's d_ptr could
also be nullptr, and we would dereference the null pointer.

Guarding against self-assignment is nevertheless a good practice.

Fixes static analyzer warning
5fc3780532e30c6350a0aa1ad2188a4c.

Pick-to: 6.1
Change-Id: I07ff808e4c4f5bf07b4d6663f1fb4a3301a0fec7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Volker Hilsheimer 2021-03-03 17:16:37 +01:00
parent 90b51219dd
commit 6e334a85a8
1 changed files with 5 additions and 4 deletions

View File

@ -609,10 +609,11 @@ QHostInfo::QHostInfo(const QHostInfo &other)
*/
QHostInfo &QHostInfo::operator=(const QHostInfo &other)
{
if (d_ptr)
*d_ptr = *other.d_ptr;
else
d_ptr = new QHostInfoPrivate(*other.d_ptr);
if (this == &other)
return *this;
Q_ASSERT(d_ptr && other.d_ptr);
*d_ptr = *other.d_ptr;
return *this;
}