From 0d1984357f9bc8aac671e8907208a8581a1f42db Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 26 Jul 2018 16:11:31 +0200 Subject: [*] Convert old C-Style casts Primitive types now use type(x) instead of (type)x, pointers should use appropriate long versions --- src/client/net/serverdiscovery.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/client/net/serverdiscovery.cpp') diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp index 799fcbe..1b29398 100644 --- a/src/client/net/serverdiscovery.cpp +++ b/src/client/net/serverdiscovery.cpp @@ -21,7 +21,7 @@ ServerDiscovery::ServerDiscovery(QObject *parent) /* Try to get a UDP port for server discovery */ int tries = 10; while (tries-- != 0) { - quint16 port = (quint16)(16384 + qrand() % 32768); + quint16 port = quint16(16384 + qrand() % 32768); if (_discoverySocket.bind(QHostAddress::AnyIPv4, port)) break; if (tries == 0) @@ -98,8 +98,8 @@ void ServerDiscovery::doDiscovery() if (_salt2.size() < SALT_LEN) _salt2.resize(SALT_LEN); for (int i = 0; i < SALT_LEN; ++i) { - salt1[i] = (char)(qrand() & 0xff); - _salt2[i] = (char)(qrand() & 0xff); + salt1[i] = char(qrand() & 0xff); + _salt2[i] = char(qrand() & 0xff); } _packet.reset(); _packet.setField(_HASH, genSha1(&_nameBytes, &salt1, &iplist)); @@ -154,7 +154,7 @@ void ServerDiscovery::onUdpReadyRead() continue; _packet.reset(); - if (_packet.readMessage(data, (quint32)size) != NM_READ_OK) + if (_packet.readMessage(data, quint32(size)) != NM_READ_OK) continue; // Valid packet, process it: @@ -183,7 +183,11 @@ void ServerDiscovery::onUdpReadyRead() << addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes; // Tell that a server hs been found - emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert, (_mgrIP == addr)); + bool ok = false; + const ushort iport = QString::fromUtf8(port).toUShort(&ok); + if (ok) { + emit serverDetected(addr.toString(), quint16(iport), _nameBytes, cert, (_mgrIP == addr)); + } // Stop the discovery this->stop(); -- cgit v1.2.3-55-g7522