Make QIPAddressUtils::toString() const-correct for IPv6

The IPv4 overload takes a IPv4Address, which is just an quint32, so it
doesn't matter whether clients call it with a const or a mutable
argument.

The IPv6 overload, OTOH, took a IPv6Address, which is a typedef for
quint8[16]. This allows users to pass a quint16[16], but not a const
quint8[16], because that would lose the const. The function, however,
doesn't modify the argument, so it could be const.

Make it so, even though, due to the typedef, it looks like a redundant
top-level const.

Change-Id: I0506f6f9026ad616c4450fceb45fea137ac27692
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2019-06-15 18:07:37 +02:00
parent f2bd46d1df
commit d0b3aaecd9
2 changed files with 2 additions and 2 deletions

View File

@ -256,7 +256,7 @@ static inline QChar toHex(uchar c)
return QChar::fromLatin1(QtMiscUtils::toHexLower(c));
}
void toString(QString &appendTo, IPv6Address address)
void toString(QString &appendTo, const IPv6Address address)
{
// the longest IPv6 address possible is:
// "1111:2222:3333:4444:5555:6666:255.255.255.255"

View File

@ -64,7 +64,7 @@ typedef quint8 IPv6Address[16];
Q_CORE_EXPORT bool parseIp4(IPv4Address &address, const QChar *begin, const QChar *end);
Q_CORE_EXPORT const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end);
Q_CORE_EXPORT void toString(QString &appendTo, IPv4Address address);
Q_CORE_EXPORT void toString(QString &appendTo, IPv6Address address);
Q_CORE_EXPORT void toString(QString &appendTo, const IPv6Address address);
} // namespace