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/main.cpp | 2 +- src/client/net/serverconnection.cpp | 6 +++--- src/client/net/serverdiscovery.cpp | 14 +++++++++----- src/client/vnc/vncthread.cpp | 8 ++++---- 4 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src/client') diff --git a/src/client/main.cpp b/src/client/main.cpp index 61ca0e9..eefd0d8 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char** argv) { ClientApp app(argc, argv); - qsrand((uint)QDateTime::currentMSecsSinceEpoch()); + qsrand(uint(QDateTime::currentMSecsSinceEpoch())); /* here we handle the arguments that were not handled by ClientApp */ for (QString a : app.arguments()) { diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp index 6350418..ca19c76 100644 --- a/src/client/net/serverconnection.cpp +++ b/src/client/net/serverconnection.cpp @@ -33,7 +33,7 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons SLOT(sslErrors(const QList &)) ); connect(_socket, &QSslSocket::peerVerifyError, [=](const QSslError &error) { qDebug() << "PVE:" << error.errorString(); }); - qDebug("Connecting to %s on port %d", host.toUtf8().data(), (int)port); + qDebug("Connecting to %s on port %d", host.toUtf8().data(), int(port)); _socket->ignoreSslErrors(); _socket->connectToHostEncrypted(host, port); _timerId = startTimer(4000); @@ -112,7 +112,7 @@ void ServerConnection::handleMsg() emit stateChange(ConnectWindow::AwaitingChallengeResponse); _myChallenge.resize(CHALLENGE_LEN); for (int i = 0; i < CHALLENGE_LEN; ++i) { - _myChallenge[i] = (char)(qrand() & 0xff); + _myChallenge[i] = char(qrand() & 0xff); } QByteArray serverChallenge(_fromServer.getFieldBytes(_CHALLENGE)); _toServer.reset(); @@ -407,7 +407,7 @@ void ServerConnection::sock_closed() void ServerConnection::sock_error(QAbstractSocket::SocketError errcode) { - qDebug("Connection error: %d", (int)errcode); + qDebug("Connection error: %d", int(errcode)); this->disconnectFromServer(); } 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(); diff --git a/src/client/vnc/vncthread.cpp b/src/client/vnc/vncthread.cpp index e399e9b..1a903d5 100644 --- a/src/client/vnc/vncthread.cpp +++ b/src/client/vnc/vncthread.cpp @@ -89,7 +89,7 @@ void VncThread::run() _client->frameBuffer = nullptr; // save this instance in vnc-struct for callbacks - rfbClientSetClientData(_client, 0, this); + rfbClientSetClientData(_client, nullptr, this); // start client if (rfbInitClient(_client, nullptr, nullptr)) { @@ -172,7 +172,7 @@ void VncThread::emitStarted() */ char* VncThread::passwdHandler(rfbClient *client) { - VncThread* t = (VncThread*)rfbClientGetClientData(client, 0); + VncThread* t = reinterpret_cast(rfbClientGetClientData(client, nullptr)); return strdup(t->_passwd.toUtf8()); } @@ -185,7 +185,7 @@ char* VncThread::passwdHandler(rfbClient *client) */ rfbBool VncThread::frameBufferHandler(rfbClient *client) { - VncThread *t = (VncThread*)rfbClientGetClientData(client, 0); + VncThread *t = reinterpret_cast(rfbClientGetClientData(client, nullptr)); const int width = client->width, height = client->height, depth = 32; const int size = width * height * (depth / 8); qDebug("[%s] Remote desktop: %ix%ix%i", t->metaObject()->className(), width, height, depth); @@ -201,7 +201,7 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client) ::exit(1); } client->frameBuffer = t->_img->bits(); - memset(client->frameBuffer, '\0', (size_t)size); + memset(client->frameBuffer, '\0', size_t(size)); client->format.trueColour = 1; client->format.bitsPerPixel = depth; client->format.redShift = 16; -- cgit v1.2.3-55-g7522