QHostAddress::setAddress - fix an overload taking SpecialAddress
It must detach, otherwise it overwrites all QHostAddresses that were sharing a given QHostAddressPrivate. This overload was introduced in 5.8 and probably as a result broke some pre-existing code, that previously was using a conversion and the correctly working setAddress. Conveniently, QHostAddress::clear() does: d.detach(); d->clear();, exactly the first thing we do in other overloads of setAddress. Task-number: QTBUG-63764 Change-Id: I63c36e877c9358d3ff26ba1f2e4adf35b771f426 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5fa6438633
commit
7809bba68f
@ -518,49 +518,6 @@ QHostAddress::QHostAddress(SpecialAddress address)
|
||||
setAddress(address);
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
\since 5.8
|
||||
|
||||
Sets the special address specified by \a address.
|
||||
*/
|
||||
void QHostAddress::setAddress(SpecialAddress address)
|
||||
{
|
||||
d->clear();
|
||||
|
||||
Q_IPV6ADDR ip6;
|
||||
memset(&ip6, 0, sizeof ip6);
|
||||
quint32 ip4 = INADDR_ANY;
|
||||
|
||||
switch (address) {
|
||||
case Null:
|
||||
return;
|
||||
|
||||
case Broadcast:
|
||||
ip4 = INADDR_BROADCAST;
|
||||
break;
|
||||
case LocalHost:
|
||||
ip4 = INADDR_LOOPBACK;
|
||||
break;
|
||||
case AnyIPv4:
|
||||
break;
|
||||
|
||||
case LocalHostIPv6:
|
||||
ip6[15] = 1;
|
||||
Q_FALLTHROUGH();
|
||||
case AnyIPv6:
|
||||
d->setAddress(ip6);
|
||||
return;
|
||||
|
||||
case Any:
|
||||
d->protocol = QAbstractSocket::AnyIPProtocol;
|
||||
return;
|
||||
}
|
||||
|
||||
// common IPv4 part
|
||||
d->setAddress(ip4);
|
||||
}
|
||||
|
||||
/*!
|
||||
Destroys the host address object.
|
||||
*/
|
||||
@ -724,6 +681,49 @@ void QHostAddress::setAddress(const struct sockaddr *sockaddr)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
\since 5.8
|
||||
|
||||
Sets the special address specified by \a address.
|
||||
*/
|
||||
void QHostAddress::setAddress(SpecialAddress address)
|
||||
{
|
||||
clear();
|
||||
|
||||
Q_IPV6ADDR ip6;
|
||||
memset(&ip6, 0, sizeof ip6);
|
||||
quint32 ip4 = INADDR_ANY;
|
||||
|
||||
switch (address) {
|
||||
case Null:
|
||||
return;
|
||||
|
||||
case Broadcast:
|
||||
ip4 = INADDR_BROADCAST;
|
||||
break;
|
||||
case LocalHost:
|
||||
ip4 = INADDR_LOOPBACK;
|
||||
break;
|
||||
case AnyIPv4:
|
||||
break;
|
||||
|
||||
case LocalHostIPv6:
|
||||
ip6[15] = 1;
|
||||
Q_FALLTHROUGH();
|
||||
case AnyIPv6:
|
||||
d->setAddress(ip6);
|
||||
return;
|
||||
|
||||
case Any:
|
||||
d->protocol = QAbstractSocket::AnyIPProtocol;
|
||||
return;
|
||||
}
|
||||
|
||||
// common IPv4 part
|
||||
d->setAddress(ip4);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the IPv4 address as a number.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user