From 9ba63d1460db41c219b638212b42476164fcfdff Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 24 Jul 2018 13:08:25 +0200 Subject: Update code style, fix compiler warnings - Use nullptr instead of NULL for better warnings in case of mistakes - Get rid of VLAs which are not in C++11 actually - Fix implicit signed <-> unsigned mismatches by adding checks and casts --- src/client/vnc/vncthread.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/client/vnc/vncthread.cpp') diff --git a/src/client/vnc/vncthread.cpp b/src/client/vnc/vncthread.cpp index 1dbe005..e399e9b 100644 --- a/src/client/vnc/vncthread.cpp +++ b/src/client/vnc/vncthread.cpp @@ -36,7 +36,7 @@ VncThread::VncThread(QString host, int port, QString passwd, int quality) : _port = port; _passwd = passwd; _quality = quality; - _client = NULL; + _client = nullptr; _connected = false; moveToThread(this); } @@ -45,7 +45,7 @@ VncThread::~VncThread() { qDebug("VNC worker destructor called."); Q_ASSERT(_run == false); - if (_client != NULL) { + if (_client != nullptr) { if (_client->sock != -1) ::close(_client->sock); _client->sock = -1; @@ -82,27 +82,27 @@ void VncThread::run() _client->canHandleNewFBSize = true; free(_client->serverHost); // in rfbGetClient, serverHost is assigned strdup(""), so free that first. _client->serverHost = strdup(_host.toUtf8().constData()); - _client->desktopName = NULL; + _client->desktopName = nullptr; _client->serverPort = _port; _client->GetPassword = &passwdHandler; _client->GotFrameBufferUpdate = &updateImage; - _client->frameBuffer = NULL; + _client->frameBuffer = nullptr; // save this instance in vnc-struct for callbacks rfbClientSetClientData(_client, 0, this); // start client - if (rfbInitClient(_client, NULL, NULL)) { + if (rfbInitClient(_client, nullptr, nullptr)) { break; // Success! } // Connection failed - _client = NULL; // InitClient frees the client on failure, so make sure we don't keep an invalid pointer around + _client = nullptr; // InitClient frees the client on failure, so make sure we don't keep an invalid pointer around if (!_run) break; // error, let's try again this->msleep(10 + qrand() % 50); } - if (_client != NULL) { + if (_client != nullptr) { qDebug("[%s] Connection successful!", metaObject()->className()); int one = 1; setsockopt(_client->sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one)); @@ -136,7 +136,7 @@ void VncThread::run() */ const QString VncThread::getDesktopName() const { - if (_client == NULL || _client->desktopName == NULL) + if (_client == nullptr || _client->desktopName == nullptr) return QString(); return QString(_client->desktopName); } @@ -189,6 +189,11 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client) 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); + if (width < 0 || height < 0 || size < 0) { + qWarning() << "IGNORING INVALID FRAMEBUFFER SIZE"; + client->frameBuffer = nullptr; + return false; + } t->_img = QSharedPointer(new QImage(width, height, QImage::Format_RGB32)); if (size > t->_img->byteCount()) { @@ -196,7 +201,7 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client) ::exit(1); } client->frameBuffer = t->_img->bits(); - memset(client->frameBuffer, '\0', 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