diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-03-03 17:16:37 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-03-04 05:49:15 +0000 |
commit | 69951fec45e7b630b86989295399c980803f9b1b (patch) | |
tree | 22ba6f6c6185a0e87ef7cde5bc51ff1fc2b7c34f /src | |
parent | 5af06405a61a571fd79f186bf535d9fab957bec1 (diff) |
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.
Change-Id: I07ff808e4c4f5bf07b4d6663f1fb4a3301a0fec7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 6e334a85a82f1fedc39f54511a9d1b0c7b512d5b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index b3d6844e43..fbc3248815 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -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; } |