diff options
Diffstat (limited to 'common')
145 files changed, 896 insertions, 930 deletions
diff --git a/common/network/Socket.cxx b/common/network/Socket.cxx index 78484f51..8da44366 100644 --- a/common/network/Socket.cxx +++ b/common/network/Socket.cxx @@ -71,7 +71,7 @@ bool network::isSocketListening(int sock) } Socket::Socket(int fd) - : instream(0), outstream(0), + : instream(nullptr), outstream(nullptr), isShutdown_(false), queryConnection(false) { initSockets(); @@ -79,7 +79,7 @@ Socket::Socket(int fd) } Socket::Socket() - : instream(0), outstream(0), + : instream(nullptr), outstream(nullptr), isShutdown_(false), queryConnection(false) { initSockets(); @@ -128,14 +128,14 @@ void Socket::setFd(int fd) isShutdown_ = false; } -SocketListener::SocketListener(int fd) - : fd(fd), filter(0) +SocketListener::SocketListener(int fd_) + : fd(fd_), filter(nullptr) { initSockets(); } SocketListener::SocketListener() - : fd(-1), filter(0) + : fd(-1), filter(nullptr) { initSockets(); } @@ -160,14 +160,14 @@ Socket* SocketListener::accept() { int new_sock = -1; // Accept an incoming connection - if ((new_sock = ::accept(fd, 0, 0)) < 0) + if ((new_sock = ::accept(fd, nullptr, nullptr)) < 0) throw SocketException("unable to accept new connection", errorNumber); // Create the socket object & check connection is allowed Socket* s = createSocket(new_sock); if (filter && !filter->verifyConnection(s)) { delete s; - return NULL; + return nullptr; } return s; diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 15730cfd..3f2f0f1f 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -129,17 +129,17 @@ TcpSocket::TcpSocket(const char *host, int port) memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - hints.ai_canonname = NULL; - hints.ai_addr = NULL; - hints.ai_next = NULL; + hints.ai_canonname = nullptr; + hints.ai_addr = nullptr; + hints.ai_next = nullptr; - if ((result = getaddrinfo(host, NULL, &hints, &ai)) != 0) { + if ((result = getaddrinfo(host, nullptr, &hints, &ai)) != 0) { throw GAIException("unable to resolve host by name", result); } sock = -1; err = 0; - for (current = ai; current != NULL; current = current->ai_next) { + for (current = ai; current != nullptr; current = current->ai_next) { int family; vnc_sockaddr_t sa; socklen_t salen; @@ -168,7 +168,7 @@ TcpSocket::TcpSocket(const char *host, int port) else sa.u.sin6.sin6_port = htons(port); - getnameinfo(&sa.u.sa, salen, ntop, sizeof(ntop), NULL, 0, NI_NUMERICHOST); + getnameinfo(&sa.u.sa, salen, ntop, sizeof(ntop), nullptr, 0, NI_NUMERICHOST); vlog.debug("Connecting to %s [%s] port %d", host, ntop, port); sock = socket (family, SOCK_STREAM, 0); @@ -228,7 +228,7 @@ const char* TcpSocket::getPeerAddress() { buffer[0] = '['; ret = getnameinfo(&sa.u.sa, sizeof(sa.u.sin6), - buffer + 1, sizeof(buffer) - 2, NULL, 0, + buffer + 1, sizeof(buffer) - 2, nullptr, 0, NI_NUMERICHOST); if (ret != 0) { vlog.error("unable to convert peer name to a string"); @@ -244,7 +244,7 @@ const char* TcpSocket::getPeerAddress() { char *name; name = inet_ntoa(sa.u.sin.sin_addr); - if (name == NULL) { + if (name == nullptr) { vlog.error("unable to convert peer name to a string"); return "(N/A)"; } @@ -338,8 +338,8 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr, listen(sock); } -Socket* TcpListener::createSocket(int fd) { - return new TcpSocket(fd); +Socket* TcpListener::createSocket(int fd_) { + return new TcpSocket(fd_); } std::list<std::string> TcpListener::getMyAddresses() { @@ -352,15 +352,15 @@ std::list<std::string> TcpListener::getMyAddresses() { hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - hints.ai_canonname = NULL; - hints.ai_addr = NULL; - hints.ai_next = NULL; + hints.ai_canonname = nullptr; + hints.ai_addr = nullptr; + hints.ai_next = nullptr; // Windows doesn't like NULL for service, so specify something - if ((getaddrinfo(NULL, "1", &hints, &ai)) != 0) + if ((getaddrinfo(nullptr, "1", &hints, &ai)) != 0) return result; - for (current= ai; current != NULL; current = current->ai_next) { + for (current= ai; current != nullptr; current = current->ai_next) { char addr[INET6_ADDRSTRLEN]; switch (current->ai_family) { @@ -377,7 +377,7 @@ std::list<std::string> TcpListener::getMyAddresses() { } getnameinfo(current->ai_addr, current->ai_addrlen, addr, INET6_ADDRSTRLEN, - NULL, 0, NI_NUMERICHOST); + nullptr, 0, NI_NUMERICHOST); result.push_back(addr); } @@ -417,7 +417,7 @@ void network::createLocalTcpListeners(std::list<SocketListener*> *listeners, ai[1].ai_family = sa[1].u.sin6.sin6_family; ai[1].ai_addr = &sa[1].u.sa; ai[1].ai_addrlen = sizeof(sa[1].u.sin6); - ai[1].ai_next = NULL; + ai[1].ai_next = nullptr; createTcpListeners(listeners, ai); } @@ -436,9 +436,9 @@ void network::createTcpListeners(std::list<SocketListener*> *listeners, hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - hints.ai_canonname = NULL; - hints.ai_addr = NULL; - hints.ai_next = NULL; + hints.ai_canonname = nullptr; + hints.ai_addr = nullptr; + hints.ai_next = nullptr; snprintf (service, sizeof (service) - 1, "%d", port); service[sizeof (service) - 1] = '\0'; @@ -463,7 +463,7 @@ void network::createTcpListeners(std::list<SocketListener*> *listeners, initSockets(); - for (current = ai; current != NULL; current = current->ai_next) { + for (current = ai; current != nullptr; current = current->ai_next) { switch (current->ai_family) { case AF_INET: if (!UseIPv4) @@ -629,7 +629,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { parts[0].erase(parts.size()-1, 1); } - if ((result = getaddrinfo (parts[0].c_str(), NULL, &hints, &ai)) != 0) { + if ((result = getaddrinfo (parts[0].c_str(), nullptr, &hints, &ai)) != 0) { throw GAIException("unable to resolve host by name", result); } @@ -711,11 +711,11 @@ std::string TcpFilter::patternToStr(const TcpFilter::Pattern& p) { if (p.address.u.sa.sa_family == AF_INET) { getnameinfo(&p.address.u.sa, sizeof(p.address.u.sin), - addr, sizeof(addr), NULL, 0, NI_NUMERICHOST); + addr, sizeof(addr), nullptr, 0, NI_NUMERICHOST); } else if (p.address.u.sa.sa_family == AF_INET6) { addr[0] = '['; getnameinfo(&p.address.u.sa, sizeof(p.address.u.sin6), - addr + 1, sizeof(addr) - 2, NULL, 0, NI_NUMERICHOST); + addr + 1, sizeof(addr) - 2, nullptr, 0, NI_NUMERICHOST); strcat(addr, "]"); } else addr[0] = '\0'; diff --git a/common/network/TcpSocket.h b/common/network/TcpSocket.h index c62dd78b..b029bff2 100644 --- a/common/network/TcpSocket.h +++ b/common/network/TcpSocket.h @@ -56,8 +56,8 @@ namespace network { TcpSocket(int sock); TcpSocket(const char *name, int port); - virtual const char* getPeerAddress(); - virtual const char* getPeerEndpoint(); + const char* getPeerAddress() override; + const char* getPeerEndpoint() override; protected: bool enableNagles(bool enable); @@ -68,12 +68,12 @@ namespace network { TcpListener(const struct sockaddr *listenaddr, socklen_t listenaddrlen); TcpListener(int sock); - virtual int getMyPort(); + int getMyPort() override; static std::list<std::string> getMyAddresses(); protected: - virtual Socket* createSocket(int fd); + Socket* createSocket(int fd) override; }; void createLocalTcpListeners(std::list<SocketListener*> *listeners, @@ -97,7 +97,7 @@ namespace network { TcpFilter(const char* filter); virtual ~TcpFilter(); - virtual bool verifyConnection(Socket* s); + bool verifyConnection(Socket* s) override; typedef enum {Accept, Reject, Query} Action; struct Pattern { diff --git a/common/network/UnixSocket.cxx b/common/network/UnixSocket.cxx index e7793849..3a422b6c 100644 --- a/common/network/UnixSocket.cxx +++ b/common/network/UnixSocket.cxx @@ -157,8 +157,8 @@ UnixListener::~UnixListener() unlink(addr.sun_path); } -Socket* UnixListener::createSocket(int fd) { - return new UnixSocket(fd); +Socket* UnixListener::createSocket(int fd_) { + return new UnixSocket(fd_); } int UnixListener::getMyPort() { diff --git a/common/network/UnixSocket.h b/common/network/UnixSocket.h index e66afcd1..3ecc6179 100644 --- a/common/network/UnixSocket.h +++ b/common/network/UnixSocket.h @@ -38,8 +38,8 @@ namespace network { UnixSocket(int sock); UnixSocket(const char *name); - virtual const char* getPeerAddress(); - virtual const char* getPeerEndpoint(); + const char* getPeerAddress() override; + const char* getPeerEndpoint() override; }; class UnixListener : public SocketListener { @@ -47,10 +47,10 @@ namespace network { UnixListener(const char *listenaddr, int mode); virtual ~UnixListener(); - int getMyPort(); + int getMyPort() override; protected: - virtual Socket* createSocket(int fd); + Socket* createSocket(int fd) override; }; } diff --git a/common/os/Mutex.cxx b/common/os/Mutex.cxx index e6532a7d..2a768b4c 100644 --- a/common/os/Mutex.cxx +++ b/common/os/Mutex.cxx @@ -41,7 +41,7 @@ Mutex::Mutex() int ret; systemMutex = new pthread_mutex_t; - ret = pthread_mutex_init((pthread_mutex_t*)systemMutex, NULL); + ret = pthread_mutex_init((pthread_mutex_t*)systemMutex, nullptr); if (ret != 0) throw rdr::SystemException("Failed to create mutex", ret); #endif @@ -84,9 +84,9 @@ void Mutex::unlock() #endif } -Condition::Condition(Mutex* mutex) +Condition::Condition(Mutex* mutex_) { - this->mutex = mutex; + this->mutex = mutex_; #ifdef WIN32 systemCondition = new CONDITION_VARIABLE; @@ -95,7 +95,7 @@ Condition::Condition(Mutex* mutex) int ret; systemCondition = new pthread_cond_t; - ret = pthread_cond_init((pthread_cond_t*)systemCondition, NULL); + ret = pthread_cond_init((pthread_cond_t*)systemCondition, nullptr); if (ret != 0) throw rdr::SystemException("Failed to create condition variable", ret); #endif diff --git a/common/os/Thread.cxx b/common/os/Thread.cxx index 92cc68d5..91f7fd07 100644 --- a/common/os/Thread.cxx +++ b/common/os/Thread.cxx @@ -35,7 +35,7 @@ using namespace os; -Thread::Thread() : running(false), threadId(NULL) +Thread::Thread() : running(false), threadId(nullptr) { mutex = new Mutex; @@ -64,8 +64,8 @@ void Thread::start() AutoMutex a(mutex); #ifdef WIN32 - *(HANDLE*)threadId = CreateThread(NULL, 0, startRoutine, this, 0, NULL); - if (*(HANDLE*)threadId == NULL) + *(HANDLE*)threadId = CreateThread(nullptr, 0, startRoutine, this, 0, nullptr); + if (*(HANDLE*)threadId == nullptr) throw rdr::SystemException("Failed to create thread", GetLastError()); #else int ret; @@ -78,9 +78,9 @@ void Thread::start() if (ret != 0) throw rdr::SystemException("Failed to mask signals", ret); - ret = pthread_create((pthread_t*)threadId, NULL, startRoutine, this); + ret = pthread_create((pthread_t*)threadId, nullptr, startRoutine, this); - pthread_sigmask(SIG_SETMASK, &old, NULL); + pthread_sigmask(SIG_SETMASK, &old, nullptr); if (ret != 0) throw rdr::SystemException("Failed to create thread", ret); @@ -103,7 +103,7 @@ void Thread::wait() #else int ret; - ret = pthread_join(*(pthread_t*)threadId, NULL); + ret = pthread_join(*(pthread_t*)threadId, nullptr); if (ret != 0) throw rdr::SystemException("Failed to join thread", ret); #endif @@ -165,5 +165,9 @@ void* Thread::startRoutine(void* data) self->running = false; self->mutex->unlock(); +#ifdef WIN32 return 0; +#else + return nullptr; +#endif } diff --git a/common/os/os.cxx b/common/os/os.cxx index 83995d0d..2ac70550 100644 --- a/common/os/os.cxx +++ b/common/os/os.cxx @@ -58,12 +58,12 @@ static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_ #ifndef WIN32 homedir = getenv("HOME"); - if (homedir == NULL) { + if (homedir == nullptr) { uid = getuid(); passwd = getpwuid(uid); - if (passwd == NULL) { + if (passwd == nullptr) { /* Do we want emit error msg here? */ - return NULL; + return nullptr; } homedir = passwd->pw_dir; } @@ -72,7 +72,7 @@ static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_ return homedir; xdgdir = getenv(xdg_env); - if (xdgdir != NULL && xdgdir[0] == '/') + if (xdgdir != nullptr && xdgdir[0] == '/') snprintf(dir, sizeof(dir), "%s/tigervnc", xdgdir); else snprintf(dir, sizeof(dir), "%s/%s/tigervnc", homedir, xdg_def); @@ -83,25 +83,25 @@ static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_ (void) xdg_env; if (userDir) - ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_PROFILE, FALSE); + ret = SHGetSpecialFolderPath(nullptr, dir, CSIDL_PROFILE, FALSE); else - ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, FALSE); + ret = SHGetSpecialFolderPath(nullptr, dir, CSIDL_APPDATA, FALSE); if (ret == FALSE) - return NULL; + return nullptr; if (userDir) return dir; - ret = SHGetSpecialFolderPath(NULL, legacy, CSIDL_APPDATA, FALSE); + ret = SHGetSpecialFolderPath(nullptr, legacy, CSIDL_APPDATA, FALSE); if (ret == FALSE) - return NULL; + return nullptr; if (strlen(dir) + strlen("\\TigerVNC") >= sizeof(dir)) - return NULL; + return nullptr; if (strlen(legacy) + strlen("\\vnc") >= sizeof(legacy)) - return NULL; + return nullptr; strcat(dir, "\\TigerVNC"); strcat(legacy, "\\vnc"); @@ -111,7 +111,7 @@ static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_ const char* os::getuserhomedir() { - return getvncdir(true, NULL, NULL); + return getvncdir(true, nullptr, nullptr); } const char* os::getvncconfigdir() diff --git a/common/rdr/AESInStream.cxx b/common/rdr/AESInStream.cxx index de91a3df..d6d944a3 100644 --- a/common/rdr/AESInStream.cxx +++ b/common/rdr/AESInStream.cxx @@ -45,15 +45,15 @@ bool AESInStream::fillBuffer() { if (!in->hasData(2)) return false; - const uint8_t* ptr = in->getptr(2); - size_t length = ((int)ptr[0] << 8) | (int)ptr[1]; + const uint8_t* buf = in->getptr(2); + size_t length = ((int)buf[0] << 8) | (int)buf[1]; if (!in->hasData(2 + length + 16)) return false; ensureSpace(length); - ptr = in->getptr(2 + length + 16); - const uint8_t* ad = ptr; - const uint8_t* data = ptr + 2; - const uint8_t* mac = ptr + 2 + length; + buf = in->getptr(2 + length + 16); + const uint8_t* ad = buf; + const uint8_t* data = buf + 2; + const uint8_t* mac = buf + 2 + length; uint8_t macComputed[16]; if (keySize == 128) { diff --git a/common/rdr/AESInStream.h b/common/rdr/AESInStream.h index 6069bb71..f0e6de53 100644 --- a/common/rdr/AESInStream.h +++ b/common/rdr/AESInStream.h @@ -33,7 +33,7 @@ namespace rdr { virtual ~AESInStream(); private: - virtual bool fillBuffer(); + bool fillBuffer() override; int keySize; InStream* in; diff --git a/common/rdr/AESOutStream.h b/common/rdr/AESOutStream.h index f9e4f4da..c84ee2b8 100644 --- a/common/rdr/AESOutStream.h +++ b/common/rdr/AESOutStream.h @@ -31,11 +31,11 @@ namespace rdr { AESOutStream(OutStream* out, const uint8_t* key, int keySize); virtual ~AESOutStream(); - virtual void flush(); - virtual void cork(bool enable); + void flush() override; + void cork(bool enable) override; private: - virtual bool flushBuffer(); + bool flushBuffer() override; void writeMessage(const uint8_t* data, size_t length); int keySize; diff --git a/common/rdr/BufferedInStream.cxx b/common/rdr/BufferedInStream.cxx index 5978a8c9..3c04bafc 100644 --- a/common/rdr/BufferedInStream.cxx +++ b/common/rdr/BufferedInStream.cxx @@ -35,7 +35,7 @@ BufferedInStream::BufferedInStream() : bufSize(DEFAULT_BUF_SIZE), offset(0) { ptr = end = start = new uint8_t[bufSize]; - gettimeofday(&lastSizeCheck, NULL); + gettimeofday(&lastSizeCheck, nullptr); peakUsage = 0; } @@ -80,7 +80,7 @@ void BufferedInStream::ensureSpace(size_t needed) end = newBuffer + (end - ptr); ptr = start = newBuffer; - gettimeofday(&lastSizeCheck, NULL); + gettimeofday(&lastSizeCheck, nullptr); peakUsage = needed; } @@ -88,7 +88,7 @@ void BufferedInStream::ensureSpace(size_t needed) peakUsage = needed; // Time to shrink an excessive buffer? - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); if ((avail() == 0) && (bufSize > DEFAULT_BUF_SIZE) && ((now.tv_sec < lastSizeCheck.tv_sec) || (now.tv_sec > (lastSizeCheck.tv_sec + 5)))) { @@ -105,7 +105,7 @@ void BufferedInStream::ensureSpace(size_t needed) bufSize = newSize; } - gettimeofday(&lastSizeCheck, NULL); + gettimeofday(&lastSizeCheck, nullptr); peakUsage = needed; } diff --git a/common/rdr/BufferedInStream.h b/common/rdr/BufferedInStream.h index 89b25ffb..b3d6115e 100644 --- a/common/rdr/BufferedInStream.h +++ b/common/rdr/BufferedInStream.h @@ -35,7 +35,7 @@ namespace rdr { public: virtual ~BufferedInStream(); - virtual size_t pos(); + size_t pos() override; protected: size_t availSpace() { return start + bufSize - end; } @@ -45,7 +45,7 @@ namespace rdr { private: virtual bool fillBuffer() = 0; - virtual bool overrun(size_t needed); + bool overrun(size_t needed) override; private: size_t bufSize; diff --git a/common/rdr/BufferedOutStream.cxx b/common/rdr/BufferedOutStream.cxx index 640f6007..0d6a1eb6 100644 --- a/common/rdr/BufferedOutStream.cxx +++ b/common/rdr/BufferedOutStream.cxx @@ -31,12 +31,12 @@ using namespace rdr; static const size_t DEFAULT_BUF_SIZE = 16384; static const size_t MAX_BUF_SIZE = 32 * 1024 * 1024; -BufferedOutStream::BufferedOutStream(bool emulateCork) - : bufSize(DEFAULT_BUF_SIZE), offset(0), emulateCork(emulateCork) +BufferedOutStream::BufferedOutStream(bool emulateCork_) + : bufSize(DEFAULT_BUF_SIZE), offset(0), emulateCork(emulateCork_) { ptr = start = sentUpTo = new uint8_t[bufSize]; end = start + bufSize; - gettimeofday(&lastSizeCheck, NULL); + gettimeofday(&lastSizeCheck, nullptr); peakUsage = 0; } @@ -75,7 +75,7 @@ void BufferedOutStream::flush() ptr = sentUpTo = start; // Time to shrink an excessive buffer? - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); if ((sentUpTo == ptr) && (bufSize > DEFAULT_BUF_SIZE) && ((now.tv_sec < lastSizeCheck.tv_sec) || (now.tv_sec > (lastSizeCheck.tv_sec + 5)))) { @@ -93,7 +93,7 @@ void BufferedOutStream::flush() bufSize = newSize; } - gettimeofday(&lastSizeCheck, NULL); + gettimeofday(&lastSizeCheck, nullptr); peakUsage = 0; } } @@ -156,7 +156,7 @@ void BufferedOutStream::overrun(size_t needed) sentUpTo = start = newBuffer; end = newBuffer + newSize; - gettimeofday(&lastSizeCheck, NULL); + gettimeofday(&lastSizeCheck, nullptr); peakUsage = totalNeeded; return; diff --git a/common/rdr/BufferedOutStream.h b/common/rdr/BufferedOutStream.h index 22693257..dd765dc9 100644 --- a/common/rdr/BufferedOutStream.h +++ b/common/rdr/BufferedOutStream.h @@ -35,8 +35,8 @@ namespace rdr { public: virtual ~BufferedOutStream(); - virtual size_t length(); - virtual void flush(); + size_t length() override; + void flush() override; // hasBufferedData() checks if there is any data yet to be flushed @@ -49,7 +49,7 @@ namespace rdr { virtual bool flushBuffer() = 0; - virtual void overrun(size_t needed); + void overrun(size_t needed) override; private: size_t bufSize; diff --git a/common/rdr/Exception.cxx b/common/rdr/Exception.cxx index b1e0a841..d5546274 100644 --- a/common/rdr/Exception.cxx +++ b/common/rdr/Exception.cxx @@ -51,15 +51,15 @@ Exception::Exception(const char *format, ...) { va_end(ap); } -GAIException::GAIException(const char* s, int err) - : Exception("%s", s) +GAIException::GAIException(const char* s, int err_) + : Exception("%s", s), err(err_) { strncat(str_, ": ", len-1-strlen(str_)); #ifdef _WIN32 wchar_t *currStr = new wchar_t[len-strlen(str_)]; wcsncpy(currStr, gai_strerrorW(err), len-1-strlen(str_)); WideCharToMultiByte(CP_UTF8, 0, currStr, -1, str_+strlen(str_), - len-1-strlen(str_), 0, 0); + len-1-strlen(str_), nullptr, nullptr); delete [] currStr; #else strncat(str_, gai_strerror(err), len-1-strlen(str_)); @@ -83,9 +83,9 @@ SystemException::SystemException(const char* s, int err_) #ifdef _WIN32 wchar_t *currStr = new wchar_t[len-strlen(str_)]; FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - 0, err, 0, currStr, len-1-strlen(str_), 0); + nullptr, err, 0, currStr, len-1-strlen(str_), nullptr); WideCharToMultiByte(CP_UTF8, 0, currStr, -1, str_+strlen(str_), - len-1-strlen(str_), 0, 0); + len-1-strlen(str_), nullptr, nullptr); delete [] currStr; int l = strlen(str_); diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index 2c66ffca..f1a167e5 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -26,7 +26,7 @@ namespace rdr { struct Exception { enum { len = 256 }; char str_[len]; - Exception(const char *format = 0, ...) + Exception(const char *format=nullptr, ...) __attribute__((__format__ (__printf__, 2, 3))); virtual ~Exception() {} virtual const char* str() const { return str_; } diff --git a/common/rdr/FdInStream.cxx b/common/rdr/FdInStream.cxx index 8e12f3a4..491dc008 100644 --- a/common/rdr/FdInStream.cxx +++ b/common/rdr/FdInStream.cxx @@ -88,7 +88,7 @@ size_t FdInStream::readFd(uint8_t* buf, size_t len) FD_ZERO(&fds); FD_SET(fd, &fds); - n = select(fd+1, &fds, 0, 0, &tv); + n = select(fd+1, &fds, nullptr, nullptr, &tv); } while (n < 0 && errorNumber == EINTR); if (n < 0) diff --git a/common/rdr/FdInStream.h b/common/rdr/FdInStream.h index 0f8373fe..0bd5bf19 100644 --- a/common/rdr/FdInStream.h +++ b/common/rdr/FdInStream.h @@ -37,7 +37,7 @@ namespace rdr { int getFd() { return fd; } private: - virtual bool fillBuffer(); + bool fillBuffer() override; size_t readFd(uint8_t* buf, size_t len); diff --git a/common/rdr/FdOutStream.cxx b/common/rdr/FdOutStream.cxx index 6827655f..1f60d45b 100644 --- a/common/rdr/FdOutStream.cxx +++ b/common/rdr/FdOutStream.cxx @@ -59,7 +59,7 @@ FdOutStream::FdOutStream(int fd_) #endif fd(fd_) { - gettimeofday(&lastWrite, NULL); + gettimeofday(&lastWrite, nullptr); } FdOutStream::~FdOutStream() @@ -113,7 +113,7 @@ size_t FdOutStream::writeFd(const uint8_t* data, size_t length) FD_ZERO(&fds); FD_SET(fd, &fds); - n = select(fd+1, 0, &fds, 0, &tv); + n = select(fd+1, nullptr, &fds, nullptr, &tv); } while (n < 0 && errorNumber == EINTR); if (n < 0) @@ -136,7 +136,7 @@ size_t FdOutStream::writeFd(const uint8_t* data, size_t length) if (n < 0) throw SystemException("write", errorNumber); - gettimeofday(&lastWrite, NULL); + gettimeofday(&lastWrite, nullptr); return n; } diff --git a/common/rdr/FdOutStream.h b/common/rdr/FdOutStream.h index 05fc1fed..d9f16efb 100644 --- a/common/rdr/FdOutStream.h +++ b/common/rdr/FdOutStream.h @@ -41,10 +41,10 @@ namespace rdr { unsigned getIdleTime(); - virtual void cork(bool enable); + void cork(bool enable) override; private: - virtual bool flushBuffer(); + bool flushBuffer() override; size_t writeFd(const uint8_t* data, size_t length); int fd; struct timeval lastWrite; diff --git a/common/rdr/FileInStream.cxx b/common/rdr/FileInStream.cxx index 6de1a5b2..4239a238 100644 --- a/common/rdr/FileInStream.cxx +++ b/common/rdr/FileInStream.cxx @@ -39,7 +39,7 @@ FileInStream::FileInStream(const char *fileName) FileInStream::~FileInStream(void) { if (file) { fclose(file); - file = NULL; + file = nullptr; } } diff --git a/common/rdr/FileInStream.h b/common/rdr/FileInStream.h index e13596ce..1b409e46 100644 --- a/common/rdr/FileInStream.h +++ b/common/rdr/FileInStream.h @@ -34,7 +34,7 @@ namespace rdr { ~FileInStream(void); private: - virtual bool fillBuffer(); + bool fillBuffer() override; private: FILE *file; diff --git a/common/rdr/HexInStream.h b/common/rdr/HexInStream.h index 76f91c08..c69fcd68 100644 --- a/common/rdr/HexInStream.h +++ b/common/rdr/HexInStream.h @@ -30,7 +30,7 @@ namespace rdr { virtual ~HexInStream(); private: - virtual bool fillBuffer(); + bool fillBuffer() override; private: InStream& in_stream; diff --git a/common/rdr/HexOutStream.h b/common/rdr/HexOutStream.h index 16596bf3..7c74f9de 100644 --- a/common/rdr/HexOutStream.h +++ b/common/rdr/HexOutStream.h @@ -29,11 +29,11 @@ namespace rdr { HexOutStream(OutStream& os); virtual ~HexOutStream(); - virtual void flush(); - virtual void cork(bool enable); + void flush() override; + void cork(bool enable) override; private: - virtual bool flushBuffer(); + bool flushBuffer() override; void writeBuffer(); OutStream& out_stream; diff --git a/common/rdr/InStream.h b/common/rdr/InStream.h index 019ca5a7..939439e1 100644 --- a/common/rdr/InStream.h +++ b/common/rdr/InStream.h @@ -64,7 +64,7 @@ namespace rdr { #endif if (length > (size_t)(end - ptr)) { - if (restorePoint != NULL) { + if (restorePoint != nullptr) { bool ret; size_t restoreDiff; @@ -100,21 +100,21 @@ namespace rdr { inline void setRestorePoint() { #ifdef RFB_INSTREAM_CHECK - if (restorePoint != NULL) + if (restorePoint != nullptr) throw Exception("Nested use of input stream restore point"); #endif restorePoint = ptr; } inline void clearRestorePoint() { #ifdef RFB_INSTREAM_CHECK - if (restorePoint == NULL) + if (restorePoint == nullptr) throw Exception("Incorrect clearing of input stream restore point"); #endif - restorePoint = NULL; + restorePoint = nullptr; } inline void gotoRestorePoint() { #ifdef RFB_INSTREAM_CHECK - if (restorePoint == NULL) + if (restorePoint == nullptr) throw Exception("Incorrect activation of input stream restore point"); #endif ptr = restorePoint; @@ -204,7 +204,7 @@ namespace rdr { protected: - InStream() : restorePoint(NULL) + InStream() : restorePoint(nullptr) #ifdef RFB_INSTREAM_CHECK ,checkedBytes(0) #endif diff --git a/common/rdr/MemInStream.h b/common/rdr/MemInStream.h index 61d08482..e10273b1 100644 --- a/common/rdr/MemInStream.h +++ b/common/rdr/MemInStream.h @@ -54,12 +54,12 @@ namespace rdr { delete [] start; } - size_t pos() { return ptr - start; } + size_t pos() override { return ptr - start; } void reposition(size_t pos) { ptr = start + pos; } private: - bool overrun(size_t /*needed*/) { throw EndOfStream(); } + bool overrun(size_t /*needed*/) override { throw EndOfStream(); } const uint8_t* start; bool deleteWhenDone; }; diff --git a/common/rdr/MemOutStream.h b/common/rdr/MemOutStream.h index 5ed1ccf7..9bf2b810 100644 --- a/common/rdr/MemOutStream.h +++ b/common/rdr/MemOutStream.h @@ -41,7 +41,7 @@ namespace rdr { delete [] start; } - size_t length() { return ptr - start; } + size_t length() override { return ptr - start; } void clear() { ptr = start; }; void clearAndZero() { memset(start, 0, ptr-start); clear(); } void reposition(size_t pos) { ptr = start + pos; } @@ -55,7 +55,7 @@ namespace rdr { // overrun() either doubles the buffer or adds enough space for // needed bytes. - virtual void overrun(size_t needed) { + void overrun(size_t needed) override { size_t len = ptr - start + needed; if (len < (size_t)(end - start) * 2) len = (end - start) * 2; diff --git a/common/rdr/OutStream.h b/common/rdr/OutStream.h index 8450efd0..2921b232 100644 --- a/common/rdr/OutStream.h +++ b/common/rdr/OutStream.h @@ -36,7 +36,7 @@ namespace rdr { protected: - OutStream() : ptr(NULL), end(NULL), corked(false) {} + OutStream() : ptr(nullptr), end(nullptr), corked(false) {} public: diff --git a/common/rdr/RandomStream.cxx b/common/rdr/RandomStream.cxx index 79a1a0f7..9813abdd 100644 --- a/common/rdr/RandomStream.cxx +++ b/common/rdr/RandomStream.cxx @@ -45,9 +45,11 @@ RandomStream::RandomStream() { #ifdef RFB_HAVE_WINCRYPT provider = 0; - if (!CryptAcquireContext(&provider, 0, 0, PROV_RSA_FULL, 0)) { + if (!CryptAcquireContext(&provider, nullptr, nullptr, + PROV_RSA_FULL, 0)) { if (GetLastError() == (DWORD)NTE_BAD_KEYSET) { - if (!CryptAcquireContext(&provider, 0, 0, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { + if (!CryptAcquireContext(&provider, nullptr, nullptr, + PROV_RSA_FULL, CRYPT_NEWKEYSET)) { vlog.error("unable to create keyset"); provider = 0; } @@ -68,7 +70,7 @@ RandomStream::RandomStream() #endif #endif vlog.error("no OS supplied random source - using rand()"); - seed += (unsigned int) time(0) + getpid() + getpid() * 987654 + rand(); + seed += (unsigned int) time(nullptr) + getpid() + getpid() * 987654 + rand(); srand(seed); } } diff --git a/common/rdr/RandomStream.h b/common/rdr/RandomStream.h index 521012e0..48f373c1 100644 --- a/common/rdr/RandomStream.h +++ b/common/rdr/RandomStream.h @@ -40,7 +40,7 @@ namespace rdr { virtual ~RandomStream(); private: - virtual bool fillBuffer(); + bool fillBuffer() override; private: static unsigned int seed; diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index 7ba98155..d13cee1f 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -41,7 +41,7 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) self->streamEmpty = false; delete self->saved_exception; - self->saved_exception = NULL; + self->saved_exception = nullptr; try { if (!in->hasData(1)) { @@ -72,7 +72,7 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) } TLSInStream::TLSInStream(InStream* _in, gnutls_session_t _session) - : session(_session), in(_in), saved_exception(NULL) + : session(_session), in(_in), saved_exception(nullptr) { gnutls_transport_ptr_t recv, send; @@ -83,7 +83,7 @@ TLSInStream::TLSInStream(InStream* _in, gnutls_session_t _session) TLSInStream::~TLSInStream() { - gnutls_transport_set_pull_function(session, NULL); + gnutls_transport_set_pull_function(session, nullptr); delete saved_exception; } diff --git a/common/rdr/TLSInStream.h b/common/rdr/TLSInStream.h index 5b1b716f..ca69ddde 100644 --- a/common/rdr/TLSInStream.h +++ b/common/rdr/TLSInStream.h @@ -33,7 +33,7 @@ namespace rdr { virtual ~TLSInStream(); private: - virtual bool fillBuffer(); + bool fillBuffer() override; size_t readTLS(uint8_t* buf, size_t len); static ssize_t pull(gnutls_transport_ptr_t str, void* data, size_t size); diff --git a/common/rdr/TLSOutStream.cxx b/common/rdr/TLSOutStream.cxx index a06dd285..c2f69310 100644 --- a/common/rdr/TLSOutStream.cxx +++ b/common/rdr/TLSOutStream.cxx @@ -41,7 +41,7 @@ ssize_t TLSOutStream::push(gnutls_transport_ptr_t str, const void* data, OutStream *out = self->out; delete self->saved_exception; - self->saved_exception = NULL; + self->saved_exception = nullptr; try { out->writeBytes((const uint8_t*)data, size); @@ -62,7 +62,7 @@ ssize_t TLSOutStream::push(gnutls_transport_ptr_t str, const void* data, } TLSOutStream::TLSOutStream(OutStream* _out, gnutls_session_t _session) - : session(_session), out(_out), saved_exception(NULL) + : session(_session), out(_out), saved_exception(nullptr) { gnutls_transport_ptr_t recv, send; @@ -79,7 +79,7 @@ TLSOutStream::~TLSOutStream() } catch (Exception&) { } #endif - gnutls_transport_set_push_function(session, NULL); + gnutls_transport_set_push_function(session, nullptr); delete saved_exception; } diff --git a/common/rdr/TLSOutStream.h b/common/rdr/TLSOutStream.h index 2d365f36..35714238 100644 --- a/common/rdr/TLSOutStream.h +++ b/common/rdr/TLSOutStream.h @@ -31,11 +31,11 @@ namespace rdr { TLSOutStream(OutStream* out, gnutls_session_t session); virtual ~TLSOutStream(); - virtual void flush(); - virtual void cork(bool enable); + void flush() override; + void cork(bool enable) override; private: - virtual bool flushBuffer(); + bool flushBuffer() override; size_t writeTLS(const uint8_t* data, size_t length); static ssize_t push(gnutls_transport_ptr_t str, const void* data, size_t size); diff --git a/common/rdr/ZlibInStream.cxx b/common/rdr/ZlibInStream.cxx index 6441f0a1..a90d50f7 100644 --- a/common/rdr/ZlibInStream.cxx +++ b/common/rdr/ZlibInStream.cxx @@ -29,7 +29,7 @@ using namespace rdr; ZlibInStream::ZlibInStream() - : underlying(0), zs(NULL), bytesIn(0) + : underlying(nullptr), zs(nullptr), bytesIn(0) { init(); } @@ -54,7 +54,7 @@ void ZlibInStream::flushUnderlying() skip(avail()); } - setUnderlying(NULL, 0); + setUnderlying(nullptr, 0); } void ZlibInStream::reset() @@ -65,28 +65,28 @@ void ZlibInStream::reset() void ZlibInStream::init() { - assert(zs == NULL); + assert(zs == nullptr); zs = new z_stream; - zs->zalloc = Z_NULL; - zs->zfree = Z_NULL; - zs->opaque = Z_NULL; - zs->next_in = Z_NULL; + zs->zalloc = nullptr; + zs->zfree = nullptr; + zs->opaque = nullptr; + zs->next_in = nullptr; zs->avail_in = 0; if (inflateInit(zs) != Z_OK) { delete zs; - zs = NULL; + zs = nullptr; throw Exception("ZlibInStream: inflateInit failed"); } } void ZlibInStream::deinit() { - assert(zs != NULL); - setUnderlying(NULL, 0); + assert(zs != nullptr); + setUnderlying(nullptr, 0); inflateEnd(zs); delete zs; - zs = NULL; + zs = nullptr; } bool ZlibInStream::fillBuffer() diff --git a/common/rdr/ZlibInStream.h b/common/rdr/ZlibInStream.h index cce6a6e0..a0c31161 100644 --- a/common/rdr/ZlibInStream.h +++ b/common/rdr/ZlibInStream.h @@ -44,7 +44,7 @@ namespace rdr { void init(); void deinit(); - virtual bool fillBuffer(); + bool fillBuffer() override; private: InStream* underlying; diff --git a/common/rdr/ZlibOutStream.cxx b/common/rdr/ZlibOutStream.cxx index 63820b8e..0b167711 100644 --- a/common/rdr/ZlibOutStream.cxx +++ b/common/rdr/ZlibOutStream.cxx @@ -39,10 +39,10 @@ ZlibOutStream::ZlibOutStream(OutStream* os, int compressLevel) : underlying(os), compressionLevel(compressLevel), newLevel(compressLevel) { zs = new z_stream; - zs->zalloc = Z_NULL; - zs->zfree = Z_NULL; - zs->opaque = Z_NULL; - zs->next_in = Z_NULL; + zs->zalloc = nullptr; + zs->zfree = nullptr; + zs->opaque = nullptr; + zs->next_in = nullptr; zs->avail_in = 0; if (deflateInit(zs, compressLevel) != Z_OK) { delete zs; @@ -78,14 +78,14 @@ void ZlibOutStream::setCompressionLevel(int level) void ZlibOutStream::flush() { BufferedOutStream::flush(); - if (underlying != NULL) + if (underlying != nullptr) underlying->flush(); } void ZlibOutStream::cork(bool enable) { BufferedOutStream::cork(enable); - if (underlying != NULL) + if (underlying != nullptr) underlying->cork(enable); } diff --git a/common/rdr/ZlibOutStream.h b/common/rdr/ZlibOutStream.h index 8061a58c..14df2a84 100644 --- a/common/rdr/ZlibOutStream.h +++ b/common/rdr/ZlibOutStream.h @@ -35,16 +35,16 @@ namespace rdr { public: - ZlibOutStream(OutStream* os=0, int compressionLevel=-1); + ZlibOutStream(OutStream* os=nullptr, int compressionLevel=-1); virtual ~ZlibOutStream(); void setUnderlying(OutStream* os); void setCompressionLevel(int level=-1); - virtual void flush(); - virtual void cork(bool enable); + void flush() override; + void cork(bool enable) override; private: - virtual bool flushBuffer(); + bool flushBuffer() override; void deflate(int flush); void checkCompressionLevel(); diff --git a/common/rfb/Blacklist.cxx b/common/rfb/Blacklist.cxx index 12a54c45..68420ae2 100644 --- a/common/rfb/Blacklist.cxx +++ b/common/rfb/Blacklist.cxx @@ -67,7 +67,7 @@ bool Blacklist::isBlackmarked(const char* name) { // Entry exists - has it reached the threshold yet? if ((*i).second.marks >= threshold) { // Yes - entry is blocked - has the timeout expired? - time_t now = time(0); + time_t now = time(nullptr); if (now >= (*i).second.blockUntil) { // Timeout has expired. Reset timeout and allow // a re-try. diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 0f4fc4f8..0db5f4c8 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -25,6 +25,8 @@ #include <stdio.h> #include <string.h> +#include <algorithm> + #include <rfb/Exception.h> #include <rfb/clipboardTypes.h> #include <rfb/fenceTypes.h> @@ -48,10 +50,10 @@ using namespace rfb; static LogWriter vlog("CConnection"); CConnection::CConnection() - : csecurity(0), + : csecurity(nullptr), supportsLocalCursor(false), supportsCursorPosition(false), supportsDesktopResize(false), supportsLEDState(false), - is(0), os(0), reader_(0), writer_(0), + is(nullptr), os(nullptr), reader_(nullptr), writer_(nullptr), shared(false), state_(RFBSTATE_UNINITIALISED), pendingPFChange(false), preferredEncoding(encodingTight), @@ -59,7 +61,7 @@ CConnection::CConnection() formatChange(false), encodingChange(false), firstUpdate(true), pendingUpdate(false), continuousUpdates(false), forceNonincremental(true), - framebuffer(NULL), decoder(this), + framebuffer(nullptr), decoder(this), hasRemoteClipboard(false), hasLocalClipboard(false) { } @@ -71,7 +73,7 @@ CConnection::~CConnection() void CConnection::setServerName(const char* name_) { - if (name_ == NULL) + if (name_ == nullptr) name_ = ""; serverName = name_; } @@ -91,7 +93,7 @@ void CConnection::setFramebuffer(ModifiablePixelBuffer* fb) assert(fb->height() == server.height()); } - if ((framebuffer != NULL) && (fb != NULL)) { + if ((framebuffer != nullptr) && (fb != nullptr)) { Rect rect; const uint8_t* data; @@ -226,14 +228,8 @@ bool CConnection::processSecurityTypesMsg() state_ = RFBSTATE_SECURITY_REASON; return true; } else if (secType == secTypeNone || secType == secTypeVncAuth) { - std::list<uint8_t>::iterator i; - for (i = secTypes.begin(); i != secTypes.end(); i++) - if (*i == secType) { - secType = *i; - break; - } - - if (i == secTypes.end()) + if (std::find(secTypes.begin(), secTypes.end(), + secType) == secTypes.end()) secType = secTypeInvalid; } else { vlog.error("Unknown 3.3 security type %d", secType); @@ -260,8 +256,6 @@ bool CConnection::processSecurityTypesMsg() return true; } - std::list<uint8_t>::iterator j; - for (int i = 0; i < nServerSecTypes; i++) { uint8_t serverSecType = is->readU8(); vlog.debug("Server offers security type %s(%d)", @@ -272,12 +266,10 @@ bool CConnection::processSecurityTypesMsg() * It means server's order specifies priority. */ if (secType == secTypeInvalid) { - for (j = secTypes.begin(); j != secTypes.end(); j++) - if (*j == serverSecType) { - secType = *j; - break; - } - } + if (std::find(secTypes.begin(), secTypes.end(), + serverSecType) != secTypes.end()) + secType = serverSecType; + } } // Inform the server of our decision @@ -399,13 +391,13 @@ void CConnection::close() vlog.error("%s", e.str()); } - setFramebuffer(NULL); + setFramebuffer(nullptr); delete csecurity; - csecurity = NULL; + csecurity = nullptr; delete reader_; - reader_ = NULL; + reader_ = nullptr; delete writer_; - writer_ = NULL; + writer_ = nullptr; } void CConnection::setDesktopSize(int w, int h) @@ -420,7 +412,7 @@ void CConnection::setDesktopSize(int w, int h) server.height()); resizeFramebuffer(); - assert(framebuffer != NULL); + assert(framebuffer != nullptr); assert(framebuffer->width() == server.width()); assert(framebuffer->height() == server.height()); } @@ -440,7 +432,7 @@ void CConnection::setExtendedDesktopSize(unsigned reason, server.height()); resizeFramebuffer(); - assert(framebuffer != NULL); + assert(framebuffer != nullptr); assert(framebuffer->width() == server.width()); assert(framebuffer->height() == server.height()); } @@ -471,7 +463,7 @@ void CConnection::serverInit(int width, int height, vlog.debug("initialisation done"); initDone(); - assert(framebuffer != NULL); + assert(framebuffer != nullptr); assert(framebuffer->width() == server.width()); assert(framebuffer->height() == server.height()); @@ -501,7 +493,7 @@ void CConnection::framebufferUpdateStart() { CMsgHandler::framebufferUpdateStart(); - assert(framebuffer != NULL); + assert(framebuffer != nullptr); // Note: This might not be true if continuous updates are supported pendingUpdate = false; @@ -683,7 +675,7 @@ void CConnection::sendClipboardData(const char* data) // FIXME: This conversion magic should be in CMsgWriter std::string filtered(convertCRLF(data)); size_t sizes[1] = { filtered.size() + 1 }; - const uint8_t* data[1] = { (const uint8_t*)filtered.c_str() }; + const uint8_t* datas[1] = { (const uint8_t*)filtered.c_str() }; if (unsolicitedClipboardAttempt) { unsolicitedClipboardAttempt = false; @@ -695,7 +687,7 @@ void CConnection::sendClipboardData(const char* data) } } - writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, data); + writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, datas); } else { writer()->writeClientCutText(data); } diff --git a/common/rfb/CConnection.h b/common/rfb/CConnection.h index df0fbb14..dca98a92 100644 --- a/common/rfb/CConnection.h +++ b/common/rfb/CConnection.h @@ -97,34 +97,32 @@ namespace rfb { // Note: These must be called by any deriving classes - virtual void setDesktopSize(int w, int h); - virtual void setExtendedDesktopSize(unsigned reason, unsigned result, - int w, int h, - const ScreenSet& layout); + void setDesktopSize(int w, int h) override; + void setExtendedDesktopSize(unsigned reason, unsigned result, + int w, int h, + const ScreenSet& layout) override; - virtual void endOfContinuousUpdates(); + void endOfContinuousUpdates() override; - virtual void serverInit(int width, int height, - const PixelFormat& pf, - const char* name); + void serverInit(int width, int height, const PixelFormat& pf, + const char* name) override; - virtual bool readAndDecodeRect(const Rect& r, int encoding, - ModifiablePixelBuffer* pb); + bool readAndDecodeRect(const Rect& r, int encoding, + ModifiablePixelBuffer* pb) override; - virtual void framebufferUpdateStart(); - virtual void framebufferUpdateEnd(); - virtual bool dataRect(const Rect& r, int encoding); + void framebufferUpdateStart() override; + void framebufferUpdateEnd() override; + bool dataRect(const Rect& r, int encoding) override; - virtual void serverCutText(const char* str); + void serverCutText(const char* str) override; - virtual void handleClipboardCaps(uint32_t flags, - const uint32_t* lengths); - virtual void handleClipboardRequest(uint32_t flags); - virtual void handleClipboardPeek(); - virtual void handleClipboardNotify(uint32_t flags); - virtual void handleClipboardProvide(uint32_t flags, - const size_t* lengths, - const uint8_t* const* data); + void handleClipboardCaps(uint32_t flags, + const uint32_t* lengths) override; + void handleClipboardRequest(uint32_t flags) override; + void handleClipboardPeek() override; + void handleClipboardNotify(uint32_t flags) override; + void handleClipboardProvide(uint32_t flags, const size_t* lengths, + const uint8_t* const* data) override; // Methods to be overridden in a derived class @@ -249,7 +247,7 @@ namespace rfb { // responds to requests, stating no support for synchronisation. // When overriding, call CMsgHandler::fence() directly in order to // state correct support for fence flags. - virtual void fence(uint32_t flags, unsigned len, const uint8_t data[]); + void fence(uint32_t flags, unsigned len, const uint8_t data[]) override; private: bool processVersionMsg(); diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index 006645df..8bcdbfd0 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -385,7 +385,7 @@ bool CMsgReader::readExtendedClipboard(int32_t len) } zis.flushUnderlying(); - zis.setUnderlying(NULL, 0); + zis.setUnderlying(nullptr, 0); handler->handleClipboardProvide(flags, lengths, buffers); @@ -827,31 +827,31 @@ bool CMsgReader::readExtendedDesktopSize(int x, int y, int w, int h) bool CMsgReader::readLEDState() { - uint8_t state; + uint8_t ledState; if (!is->hasData(1)) return false; - state = is->readU8(); + ledState = is->readU8(); - handler->setLEDState(state); + handler->setLEDState(ledState); return true; } bool CMsgReader::readVMwareLEDState() { - uint32_t state; + uint32_t ledState; if (!is->hasData(4)) return false; - state = is->readU32(); + ledState = is->readU32(); // As luck has it, this extension uses the same bit definitions, // so no conversion required - handler->setLEDState(state); + handler->setLEDState(ledState); return true; } diff --git a/common/rfb/CMsgWriter.cxx b/common/rfb/CMsgWriter.cxx index e941aaa7..7d757968 100644 --- a/common/rfb/CMsgWriter.cxx +++ b/common/rfb/CMsgWriter.cxx @@ -65,12 +65,11 @@ void CMsgWriter::writeSetPixelFormat(const PixelFormat& pf) void CMsgWriter::writeSetEncodings(const std::list<uint32_t> encodings) { - std::list<uint32_t>::const_iterator iter; startMsg(msgTypeSetEncodings); os->pad(1); os->writeU16(encodings.size()); - for (iter = encodings.begin(); iter != encodings.end(); ++iter) - os->writeU32(*iter); + for (uint32_t encoding : encodings) + os->writeU32(encoding); endMsg(); } @@ -192,7 +191,7 @@ void CMsgWriter::writePointerEvent(const Point& pos, int buttonMask) void CMsgWriter::writeClientCutText(const char* str) { - if (strchr(str, '\r') != NULL) + if (strchr(str, '\r') != nullptr) throw Exception("Invalid carriage return in clipboard data"); std::string latin1(utf8ToLatin1(str)); diff --git a/common/rfb/CSecurityDH.cxx b/common/rfb/CSecurityDH.cxx index f6e5ded4..6d9650bd 100644 --- a/common/rfb/CSecurityDH.cxx +++ b/common/rfb/CSecurityDH.cxx @@ -47,8 +47,8 @@ using namespace rfb; const int MinKeyLength = 128; const int MaxKeyLength = 1024; -CSecurityDH::CSecurityDH(CConnection* cc) - : CSecurity(cc), keyLength(0) +CSecurityDH::CSecurityDH(CConnection* cc_) + : CSecurity(cc_), keyLength(0) { mpz_init(g); mpz_init(p); diff --git a/common/rfb/CSecurityDH.h b/common/rfb/CSecurityDH.h index d0e5e894..df33d29b 100644 --- a/common/rfb/CSecurityDH.h +++ b/common/rfb/CSecurityDH.h @@ -33,9 +33,9 @@ namespace rfb { public: CSecurityDH(CConnection* cc); virtual ~CSecurityDH(); - virtual bool processMsg(); - virtual int getType() const { return secTypeDH; } - virtual bool isSecure() const { return false; } + bool processMsg() override; + int getType() const override { return secTypeDH; } + bool isSecure() const override { return false; } private: bool readKey(); diff --git a/common/rfb/CSecurityMSLogonII.cxx b/common/rfb/CSecurityMSLogonII.cxx index d7e23715..e721cdfc 100644 --- a/common/rfb/CSecurityMSLogonII.cxx +++ b/common/rfb/CSecurityMSLogonII.cxx @@ -44,8 +44,8 @@ using namespace rfb; -CSecurityMSLogonII::CSecurityMSLogonII(CConnection* cc) - : CSecurity(cc) +CSecurityMSLogonII::CSecurityMSLogonII(CConnection* cc_) + : CSecurity(cc_) { mpz_init(g); mpz_init(p); diff --git a/common/rfb/CSecurityMSLogonII.h b/common/rfb/CSecurityMSLogonII.h index f7c83a3e..71600c85 100644 --- a/common/rfb/CSecurityMSLogonII.h +++ b/common/rfb/CSecurityMSLogonII.h @@ -33,9 +33,9 @@ namespace rfb { public: CSecurityMSLogonII(CConnection* cc); virtual ~CSecurityMSLogonII(); - virtual bool processMsg(); - virtual int getType() const { return secTypeMSLogonII; } - virtual bool isSecure() const { return false; } + bool processMsg() override; + int getType() const override { return secTypeMSLogonII; } + bool isSecure() const override { return false; } private: bool readKey(); diff --git a/common/rfb/CSecurityNone.h b/common/rfb/CSecurityNone.h index cb887914..df685d0d 100644 --- a/common/rfb/CSecurityNone.h +++ b/common/rfb/CSecurityNone.h @@ -29,9 +29,9 @@ namespace rfb { class CSecurityNone : public CSecurity { public: - CSecurityNone(CConnection* cc) : CSecurity(cc) {} - virtual bool processMsg() { return true; } - virtual int getType() const {return secTypeNone;} + CSecurityNone(CConnection* cc_) : CSecurity(cc_) {} + bool processMsg() override { return true; } + int getType() const override {return secTypeNone;} }; } #endif diff --git a/common/rfb/CSecurityPlain.h b/common/rfb/CSecurityPlain.h index add7e776..0dbf4064 100644 --- a/common/rfb/CSecurityPlain.h +++ b/common/rfb/CSecurityPlain.h @@ -26,9 +26,9 @@ namespace rfb { class CSecurityPlain : public CSecurity { public: - CSecurityPlain(CConnection* cc) : CSecurity(cc) {} - virtual bool processMsg(); - virtual int getType() const { return secTypePlain; } + CSecurityPlain(CConnection* cc_) : CSecurity(cc_) {} + bool processMsg() override; + int getType() const override { return secTypePlain; } }; } #endif diff --git a/common/rfb/CSecurityRSAAES.cxx b/common/rfb/CSecurityRSAAES.cxx index 5a4bc9c9..96d96b01 100644 --- a/common/rfb/CSecurityRSAAES.cxx +++ b/common/rfb/CSecurityRSAAES.cxx @@ -56,14 +56,14 @@ const int MaxKeyLength = 8192; using namespace rfb; -CSecurityRSAAES::CSecurityRSAAES(CConnection* cc, uint32_t _secType, +CSecurityRSAAES::CSecurityRSAAES(CConnection* cc_, uint32_t _secType, int _keySize, bool _isAllEncrypted) - : CSecurity(cc), state(ReadPublicKey), + : CSecurity(cc_), state(ReadPublicKey), keySize(_keySize), isAllEncrypted(_isAllEncrypted), secType(_secType), clientKey(), clientPublicKey(), serverKey(), - serverKeyN(NULL), serverKeyE(NULL), - clientKeyN(NULL), clientKeyE(NULL), - rais(NULL), raos(NULL), rawis(NULL), rawos(NULL) + serverKeyN(nullptr), serverKeyE(nullptr), + clientKeyN(nullptr), clientKeyE(nullptr), + rais(nullptr), raos(nullptr), rawis(nullptr), rawos(nullptr) { assert(keySize == 128 || keySize == 256); } @@ -154,7 +154,8 @@ void CSecurityRSAAES::writePublicKey() // set e = 65537 mpz_set_ui(clientPublicKey.e, 65537); if (!rsa_generate_keypair(&clientPublicKey, &clientKey, - &rs, random_func, NULL, NULL, clientKeyLength, 0)) + &rs, random_func, nullptr, nullptr, + clientKeyLength, 0)) throw AuthFailureException("failed to generate key"); clientKeyN = new uint8_t[rsaKeySize]; clientKeyE = new uint8_t[rsaKeySize]; @@ -413,10 +414,10 @@ void CSecurityRSAAES::clearSecrets() delete[] serverKeyE; delete[] clientKeyN; delete[] clientKeyE; - serverKeyN = NULL; - serverKeyE = NULL; - clientKeyN = NULL; - clientKeyE = NULL; + serverKeyN = nullptr; + serverKeyE = nullptr; + clientKeyN = nullptr; + clientKeyE = nullptr; memset(serverRandom, 0, sizeof(serverRandom)); memset(clientRandom, 0, sizeof(clientRandom)); } @@ -439,7 +440,7 @@ void CSecurityRSAAES::writeCredentials() if (subtype == secTypeRA2UserPass) (CSecurity::upg)->getUserPasswd(isSecure(), &username, &password); else - (CSecurity::upg)->getUserPasswd(isSecure(), NULL, &password); + (CSecurity::upg)->getUserPasswd(isSecure(), nullptr, &password); if (subtype == secTypeRA2UserPass) { if (username.size() > 255) diff --git a/common/rfb/CSecurityRSAAES.h b/common/rfb/CSecurityRSAAES.h index 543b0152..29bfd575 100644 --- a/common/rfb/CSecurityRSAAES.h +++ b/common/rfb/CSecurityRSAAES.h @@ -39,9 +39,9 @@ namespace rfb { CSecurityRSAAES(CConnection* cc, uint32_t secType, int keySize, bool isAllEncrypted); virtual ~CSecurityRSAAES(); - virtual bool processMsg(); - virtual int getType() const { return secType; } - virtual bool isSecure() const { return secType == secTypeRA256; } + bool processMsg() override; + int getType() const override { return secType; } + bool isSecure() const override { return secType == secTypeRA256; } static IntParameter RSAKeyLength; diff --git a/common/rfb/CSecurityStack.cxx b/common/rfb/CSecurityStack.cxx index 6b8da8dd..838d68ac 100644 --- a/common/rfb/CSecurityStack.cxx +++ b/common/rfb/CSecurityStack.cxx @@ -25,9 +25,9 @@ using namespace rfb; -CSecurityStack::CSecurityStack(CConnection* cc, int Type, +CSecurityStack::CSecurityStack(CConnection* cc_, int Type, CSecurity* s0, CSecurity* s1) - : CSecurity(cc), type(Type) + : CSecurity(cc_), type(Type) { state = 0; state0 = s0; diff --git a/common/rfb/CSecurityStack.h b/common/rfb/CSecurityStack.h index 56ac3fea..521597ec 100644 --- a/common/rfb/CSecurityStack.h +++ b/common/rfb/CSecurityStack.h @@ -28,11 +28,11 @@ namespace rfb { class CSecurityStack : public CSecurity { public: CSecurityStack(CConnection* cc, int Type, - CSecurity* s0 = NULL, CSecurity* s1 = NULL); + CSecurity* s0 = nullptr, CSecurity* s1 = nullptr); ~CSecurityStack(); - virtual bool processMsg(); - virtual int getType() const {return type;}; - virtual bool isSecure() const; + bool processMsg() override; + int getType() const override {return type;}; + bool isSecure() const override; protected: int state; CSecurity* state0; diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index 11e6dfe3..8d8b58fd 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -75,16 +75,18 @@ static const char* configdirfn(const char* fn) const char* configdir; configdir = os::getvncconfigdir(); - if (configdir == NULL) + if (configdir == nullptr) return ""; snprintf(full_path, sizeof(full_path), "%s/%s", configdir, fn); return full_path; } -CSecurityTLS::CSecurityTLS(CConnection* cc, bool _anon) - : CSecurity(cc), session(NULL), anon_cred(NULL), cert_cred(NULL), - anon(_anon), tlsis(NULL), tlsos(NULL), rawis(NULL), rawos(NULL) +CSecurityTLS::CSecurityTLS(CConnection* cc_, bool _anon) + : CSecurity(cc_), session(nullptr), + anon_cred(nullptr), cert_cred(nullptr), + anon(_anon), tlsis(nullptr), tlsos(nullptr), + rawis(nullptr), rawos(nullptr) { if (gnutls_global_init() != GNUTLS_E_SUCCESS) throw AuthFailureException("gnutls_global_init failed"); @@ -103,32 +105,32 @@ void CSecurityTLS::shutdown() if (anon_cred) { gnutls_anon_free_client_credentials(anon_cred); - anon_cred = 0; + anon_cred = nullptr; } if (cert_cred) { gnutls_certificate_free_credentials(cert_cred); - cert_cred = 0; + cert_cred = nullptr; } if (rawis && rawos) { cc->setStreams(rawis, rawos); - rawis = NULL; - rawos = NULL; + rawis = nullptr; + rawos = nullptr; } if (tlsis) { delete tlsis; - tlsis = NULL; + tlsis = nullptr; } if (tlsos) { delete tlsos; - tlsos = NULL; + tlsos = nullptr; } if (session) { gnutls_deinit(session); - session = 0; + session = nullptr; } } @@ -206,7 +208,7 @@ void CSecurityTLS::setParam() prio = (char*)malloc(strlen(Security::GnuTLSPriority) + strlen(kx_anon_priority) + 1); - if (prio == NULL) + if (prio == nullptr) throw AuthFailureException("Not enough memory for GnuTLS priority string"); strcpy(prio, Security::GnuTLSPriority); @@ -242,7 +244,7 @@ void CSecurityTLS::setParam() prio = (char*)malloc(strlen(gnutls_default_priority) + strlen(kx_anon_priority) + 1); - if (prio == NULL) + if (prio == nullptr) throw AuthFailureException("Not enough memory for GnuTLS priority string"); strcpy(prio, gnutls_default_priority); @@ -385,7 +387,7 @@ void CSecurityTLS::checkSession() /* Certificate has some user overridable problems, so TOFU time */ hostsDir = os::getvncstatedir(); - if (hostsDir == NULL) { + if (hostsDir == nullptr) { throw AuthFailureException("Could not obtain VNC state directory " "path for known hosts storage"); } @@ -393,8 +395,8 @@ void CSecurityTLS::checkSession() std::string dbPath; dbPath = (std::string)hostsDir + "/x509_known_hosts"; - err = gnutls_verify_stored_pubkey(dbPath.c_str(), NULL, - client->getServerName(), NULL, + err = gnutls_verify_stored_pubkey(dbPath.c_str(), nullptr, + client->getServerName(), nullptr, GNUTLS_CRT_X509, &cert_list[0], 0); /* Previously known? */ @@ -648,8 +650,9 @@ void CSecurityTLS::checkSession() } } - if (gnutls_store_pubkey(dbPath.c_str(), NULL, client->getServerName(), - NULL, GNUTLS_CRT_X509, &cert_list[0], 0, 0)) + if (gnutls_store_pubkey(dbPath.c_str(), nullptr, + client->getServerName(), nullptr, + GNUTLS_CRT_X509, &cert_list[0], 0, 0)) vlog.error("Failed to store server certificate to known hosts database"); vlog.info("Exception added for server host"); diff --git a/common/rfb/CSecurityTLS.h b/common/rfb/CSecurityTLS.h index b9c345cf..8688b742 100644 --- a/common/rfb/CSecurityTLS.h +++ b/common/rfb/CSecurityTLS.h @@ -38,9 +38,9 @@ namespace rfb { public: CSecurityTLS(CConnection* cc, bool _anon); virtual ~CSecurityTLS(); - virtual bool processMsg(); - virtual int getType() const { return anon ? secTypeTLSNone : secTypeX509None; } - virtual bool isSecure() const { return !anon; } + bool processMsg() override; + int getType() const override { return anon ? secTypeTLSNone : secTypeX509None; } + bool isSecure() const override { return !anon; } static StringParameter X509CA; static StringParameter X509CRL; diff --git a/common/rfb/CSecurityVeNCrypt.cxx b/common/rfb/CSecurityVeNCrypt.cxx index 3c8e91ba..19dcabc3 100644 --- a/common/rfb/CSecurityVeNCrypt.cxx +++ b/common/rfb/CSecurityVeNCrypt.cxx @@ -26,13 +26,15 @@ #include <config.h> #endif +#include <algorithm> +#include <list> + #include <rfb/Exception.h> #include <rdr/InStream.h> #include <rdr/OutStream.h> #include <rfb/CConnection.h> #include <rfb/CSecurityVeNCrypt.h> #include <rfb/LogWriter.h> -#include <list> using namespace rfb; using namespace rdr; @@ -40,8 +42,9 @@ using namespace std; static LogWriter vlog("CVeNCrypt"); -CSecurityVeNCrypt::CSecurityVeNCrypt(CConnection* cc, SecurityClient* sec) - : CSecurity(cc), csecurity(NULL), security(sec) +CSecurityVeNCrypt::CSecurityVeNCrypt(CConnection* cc_, + SecurityClient* sec) + : CSecurity(cc_), csecurity(nullptr), security(sec) { haveRecvdMajorVersion = false; haveRecvdMinorVersion = false; @@ -54,7 +57,7 @@ CSecurityVeNCrypt::CSecurityVeNCrypt(CConnection* cc, SecurityClient* sec) minorVersion = 0; chosenType = secTypeVeNCrypt; nAvailableTypes = 0; - availableTypes = NULL; + availableTypes = nullptr; } CSecurityVeNCrypt::~CSecurityVeNCrypt() @@ -156,22 +159,17 @@ bool CSecurityVeNCrypt::processMsg() if (!haveChosenType) { chosenType = secTypeInvalid; uint8_t i; - list<uint32_t>::iterator j; list<uint32_t> secTypes; secTypes = security->GetEnabledExtSecTypes(); /* Honor server's security type order */ for (i = 0; i < nAvailableTypes; i++) { - for (j = secTypes.begin(); j != secTypes.end(); j++) { - if (*j == availableTypes[i]) { - chosenType = *j; - break; - } - } - - if (chosenType != secTypeInvalid) - break; + if (std::find(secTypes.begin(), secTypes.end(), + availableTypes[i]) != secTypes.end()) { + chosenType = availableTypes[i]; + break; + } } /* Set up the stack according to the chosen type: */ diff --git a/common/rfb/CSecurityVeNCrypt.h b/common/rfb/CSecurityVeNCrypt.h index 476bf813..f73e7927 100644 --- a/common/rfb/CSecurityVeNCrypt.h +++ b/common/rfb/CSecurityVeNCrypt.h @@ -37,9 +37,9 @@ namespace rfb { CSecurityVeNCrypt(CConnection* cc, SecurityClient* sec); ~CSecurityVeNCrypt(); - virtual bool processMsg(); - int getType() const {return chosenType;} - virtual bool isSecure() const; + bool processMsg() override; + int getType() const override {return chosenType;} + bool isSecure() const override; protected: CSecurity *csecurity; diff --git a/common/rfb/CSecurityVncAuth.cxx b/common/rfb/CSecurityVncAuth.cxx index f6a5e07a..e5f842ba 100644 --- a/common/rfb/CSecurityVncAuth.cxx +++ b/common/rfb/CSecurityVncAuth.cxx @@ -54,7 +54,7 @@ bool CSecurityVncAuth::processMsg() uint8_t challenge[vncAuthChallengeSize]; is->readBytes(challenge, vncAuthChallengeSize); std::string passwd; - (CSecurity::upg)->getUserPasswd(cc->isSecure(), 0, &passwd); + (CSecurity::upg)->getUserPasswd(cc->isSecure(), nullptr, &passwd); // Calculate the correct response uint8_t key[8]; diff --git a/common/rfb/CSecurityVncAuth.h b/common/rfb/CSecurityVncAuth.h index 3f1f315b..9a9cf6e0 100644 --- a/common/rfb/CSecurityVncAuth.h +++ b/common/rfb/CSecurityVncAuth.h @@ -25,10 +25,10 @@ namespace rfb { class CSecurityVncAuth : public CSecurity { public: - CSecurityVncAuth(CConnection* cc) : CSecurity(cc) {} + CSecurityVncAuth(CConnection* cc_) : CSecurity(cc_) {} virtual ~CSecurityVncAuth() {} - virtual bool processMsg(); - virtual int getType() const {return secTypeVncAuth;}; + bool processMsg() override; + int getType() const override {return secTypeVncAuth;}; }; } #endif diff --git a/common/rfb/ClientParams.cxx b/common/rfb/ClientParams.cxx index ade99018..bc20c3d7 100644 --- a/common/rfb/ClientParams.cxx +++ b/common/rfb/ClientParams.cxx @@ -39,7 +39,7 @@ ClientParams::ClientParams() { setName(""); - cursor_ = new Cursor(0, 0, Point(), NULL); + cursor_ = new Cursor(0, 0, Point(), nullptr); clipFlags = clipboardUTF8 | clipboardRTF | clipboardHTML | clipboardRequest | clipboardNotify | clipboardProvide; diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx index 1c215c7f..f58a9c2f 100644 --- a/common/rfb/Configuration.cxx +++ b/common/rfb/Configuration.cxx @@ -48,9 +48,9 @@ static LogWriter vlog("Config"); // -=- The Global/server/viewer Configuration objects -Configuration* Configuration::global_ = 0; -Configuration* Configuration::server_ = 0; -Configuration* Configuration::viewer_ = 0; +Configuration* Configuration::global_ = nullptr; +Configuration* Configuration::server_ = nullptr; +Configuration* Configuration::viewer_ = nullptr; Configuration* Configuration::global() { if (!global_) @@ -76,13 +76,13 @@ bool Configuration::set(const char* n, const char* v, bool immutable) { return set(n, strlen(n), v, immutable); } -bool Configuration::set(const char* name, int len, +bool Configuration::set(const char* paramName, int len, const char* val, bool immutable) { VoidParameter* current = head; while (current) { if ((int)strlen(current->getName()) == len && - strncasecmp(current->getName(), name, len) == 0) + strncasecmp(current->getName(), paramName, len) == 0) { bool b = current->setParam(val); if (b && immutable) @@ -91,7 +91,7 @@ bool Configuration::set(const char* name, int len, } current = current->_next; } - return _next ? _next->set(name, len, val, immutable) : false; + return _next ? _next->set(paramName, len, val, immutable) : false; } bool Configuration::set(const char* config, bool immutable) { @@ -127,7 +127,7 @@ VoidParameter* Configuration::get(const char* param) return current; current = current->_next; } - return _next ? _next->get(param) : 0; + return _next ? _next->get(param) : nullptr; } void Configuration::list(int width, int nameWidth) { @@ -195,7 +195,7 @@ VoidParameter::VoidParameter(const char* name_, const char* desc_, ConfigurationObject co) : immutable(false), name(name_), description(desc_) { - Configuration *conf = NULL; + Configuration *conf = nullptr; switch (co) { case ConfGlobal: conf = Configuration::global(); @@ -339,7 +339,7 @@ IntParameter::IntParameter(const char* name_, const char* desc_, int v, bool IntParameter::setParam(const char* v) { if (immutable) return true; - return setParam(strtol(v, NULL, 0)); + return setParam(strtol(v, nullptr, 0)); } bool @@ -410,7 +410,8 @@ StringParameter::operator const char *() const { BinaryParameter::BinaryParameter(const char* name_, const char* desc_, const uint8_t* v, size_t l, ConfigurationObject co) -: VoidParameter(name_, desc_, co), value(0), length(0), def_value(0), def_length(0) { +: VoidParameter(name_, desc_, co), + value(nullptr), length(0), def_value(nullptr), def_length(0) { if (l) { assert(v); value = new uint8_t[l]; @@ -440,7 +441,7 @@ void BinaryParameter::setParam(const uint8_t* v, size_t len) { if (immutable) return; vlog.debug("set %s(Binary)", getName()); delete [] value; - value = NULL; + value = nullptr; length = 0; if (len) { assert(v); diff --git a/common/rfb/Configuration.h b/common/rfb/Configuration.h index d73d8005..ec8d789a 100644 --- a/common/rfb/Configuration.h +++ b/common/rfb/Configuration.h @@ -64,7 +64,8 @@ namespace rfb { class Configuration { public: // - Create a new Configuration object - Configuration(const char* name_) : name(name_), head(0), _next(0) {} + Configuration(const char* name_) + : name(name_), head(nullptr), _next(nullptr) {} // - Return the buffer containing the Configuration's name const char* getName() const { return name.c_str(); } @@ -195,12 +196,12 @@ namespace rfb { public: AliasParameter(const char* name_, const char* desc_,VoidParameter* param_, ConfigurationObject co=ConfGlobal); - virtual bool setParam(const char* value); - virtual bool setParam(); - virtual std::string getDefaultStr() const; - virtual std::string getValueStr() const; - virtual bool isBool() const; - virtual void setImmutable(); + bool setParam(const char* value) override; + bool setParam() override; + std::string getDefaultStr() const override; + std::string getValueStr() const override; + bool isBool() const override; + void setImmutable() override; private: VoidParameter* param; }; @@ -209,12 +210,12 @@ namespace rfb { public: BoolParameter(const char* name_, const char* desc_, bool v, ConfigurationObject co=ConfGlobal); - virtual bool setParam(const char* value); - virtual bool setParam(); + bool setParam(const char* value) override; + bool setParam() override; virtual void setParam(bool b); - virtual std::string getDefaultStr() const; - virtual std::string getValueStr() const; - virtual bool isBool() const; + std::string getDefaultStr() const override; + std::string getValueStr() const override; + bool isBool() const override; operator bool() const; protected: bool value; @@ -227,10 +228,10 @@ namespace rfb { int minValue=INT_MIN, int maxValue=INT_MAX, ConfigurationObject co=ConfGlobal); using VoidParameter::setParam; - virtual bool setParam(const char* value); + bool setParam(const char* value) override; virtual bool setParam(int v); - virtual std::string getDefaultStr() const; - virtual std::string getValueStr() const; + std::string getDefaultStr() const override; + std::string getValueStr() const override; operator int() const; protected: int value; @@ -244,10 +245,10 @@ namespace rfb { // be Null, and so neither can the default value! StringParameter(const char* name_, const char* desc_, const char* v, ConfigurationObject co=ConfGlobal); - virtual ~StringParameter(); - virtual bool setParam(const char* value); - virtual std::string getDefaultStr() const; - virtual std::string getValueStr() const; + ~StringParameter() override; + bool setParam(const char* value) override; + std::string getDefaultStr() const override; + std::string getValueStr() const override; operator const char*() const; protected: std::string value; @@ -260,11 +261,11 @@ namespace rfb { const uint8_t* v, size_t l, ConfigurationObject co=ConfGlobal); using VoidParameter::setParam; - virtual ~BinaryParameter(); - virtual bool setParam(const char* value); + ~BinaryParameter() override; + bool setParam(const char* value) override; virtual void setParam(const uint8_t* v, size_t l); - virtual std::string getDefaultStr() const; - virtual std::string getValueStr() const; + std::string getDefaultStr() const override; + std::string getValueStr() const override; std::vector<uint8_t> getData() const; diff --git a/common/rfb/Congestion.cxx b/common/rfb/Congestion.cxx index 1e252165..94f07055 100644 --- a/common/rfb/Congestion.cxx +++ b/common/rfb/Congestion.cxx @@ -85,11 +85,11 @@ Congestion::Congestion() : baseRTT(-1), congWindow(INITIAL_WINDOW), inSlowStart(true), safeBaseRTT(-1), measurements(0), minRTT(-1), minCongestedRTT(-1) { - gettimeofday(&lastUpdate, NULL); - gettimeofday(&lastSent, NULL); + gettimeofday(&lastUpdate, nullptr); + gettimeofday(&lastSent, nullptr); memset(&lastPong, 0, sizeof(lastPong)); - gettimeofday(&lastPongArrival, NULL); - gettimeofday(&lastAdjustment, NULL); + gettimeofday(&lastPongArrival, nullptr); + gettimeofday(&lastAdjustment, nullptr); } Congestion::~Congestion() @@ -101,7 +101,7 @@ void Congestion::updatePosition(unsigned pos) struct timeval now; unsigned delta, consumed; - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); delta = pos - lastPosition; if ((delta > 0) || (extraBuffer > 0)) @@ -121,7 +121,7 @@ void Congestion::updatePosition(unsigned pos) congWindow = __rfbmin(INITIAL_WINDOW, congWindow); baseRTT = -1; measurements = 0; - gettimeofday(&lastAdjustment, NULL); + gettimeofday(&lastAdjustment, nullptr); minRTT = minCongestedRTT = -1; inSlowStart = true; } @@ -149,7 +149,7 @@ void Congestion::sentPing() memset(&rttInfo, 0, sizeof(struct RTTInfo)); - gettimeofday(&rttInfo.tv, NULL); + gettimeofday(&rttInfo.tv, nullptr); rttInfo.pos = lastPosition; rttInfo.extra = getExtraBuffer(); rttInfo.congested = isCongested(); @@ -166,7 +166,7 @@ void Congestion::gotPong() if (pings.empty()) return; - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); rttInfo = pings.front(); pings.pop_front(); @@ -320,7 +320,7 @@ void Congestion::debugTrace(const char* filename, int fd) #ifdef __linux__ FILE *f; f = fopen(filename, "ab"); - if (f != NULL) { + if (f != nullptr) { struct tcp_info info; int buffered; socklen_t len; @@ -329,7 +329,7 @@ void Congestion::debugTrace(const char* filename, int fd) TCP_INFO, &info, &len) == 0) && (ioctl(fd, SIOCOUTQ, &buffered) == 0)) { struct timeval now; - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); fprintf(f, "%u.%06u,%u,%u,%u,%u\n", (unsigned)now.tv_sec, (unsigned)now.tv_usec, congWindow, info.tcpi_snd_cwnd * info.tcpi_snd_mss, @@ -494,7 +494,7 @@ void Congestion::updateCongestion() #endif measurements = 0; - gettimeofday(&lastAdjustment, NULL); + gettimeofday(&lastAdjustment, nullptr); minRTT = minCongestedRTT = -1; } diff --git a/common/rfb/CopyRectDecoder.h b/common/rfb/CopyRectDecoder.h index c9f9c890..51651196 100644 --- a/common/rfb/CopyRectDecoder.h +++ b/common/rfb/CopyRectDecoder.h @@ -26,14 +26,15 @@ namespace rfb { public: CopyRectDecoder(); virtual ~CopyRectDecoder(); - virtual bool readRect(const Rect& r, rdr::InStream* is, - const ServerParams& server, rdr::OutStream* os); - virtual void getAffectedRegion(const Rect& rect, const uint8_t* buffer, - size_t buflen, const ServerParams& server, - Region* region); - virtual void decodeRect(const Rect& r, const uint8_t* buffer, - size_t buflen, const ServerParams& server, - ModifiablePixelBuffer* pb); + bool readRect(const Rect& r, rdr::InStream* is, + const ServerParams& server, + rdr::OutStream* os) override; + void getAffectedRegion(const Rect& rect, const uint8_t* buffer, + size_t buflen, const ServerParams& server, + Region* region) override; + void decodeRect(const Rect& r, const uint8_t* buffer, + size_t buflen, const ServerParams& server, + ModifiablePixelBuffer* pb) override; }; } #endif diff --git a/common/rfb/Cursor.cxx b/common/rfb/Cursor.cxx index f0c72eed..fa596bc5 100644 --- a/common/rfb/Cursor.cxx +++ b/common/rfb/Cursor.cxx @@ -33,11 +33,11 @@ using namespace rfb; static LogWriter vlog("Cursor"); Cursor::Cursor(int width, int height, const Point& hotspot, - const uint8_t* data) : + const uint8_t* data_) : width_(width), height_(height), hotspot_(hotspot) { - this->data = new uint8_t[width_*height_*4]; - memcpy(this->data, data, width_*height_*4); + data = new uint8_t[width_*height_*4]; + memcpy(data, data_, width_*height_*4); } Cursor::Cursor(const Cursor& other) : diff --git a/common/rfb/Cursor.h b/common/rfb/Cursor.h index 31d6fda9..c71f5a77 100644 --- a/common/rfb/Cursor.h +++ b/common/rfb/Cursor.h @@ -62,7 +62,7 @@ namespace rfb { Rect getEffectiveRect() const { return buffer.getRect(offset); } - virtual const uint8_t* getBuffer(const Rect& r, int* stride) const; + const uint8_t* getBuffer(const Rect& r, int* stride) const override; void update(PixelBuffer* framebuffer, Cursor* cursor, const Point& pos); diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index e39a3943..ef415886 100644 --- a/common/rfb/DecodeManager.cxx +++ b/common/rfb/DecodeManager.cxx @@ -40,8 +40,8 @@ using namespace rfb; static LogWriter vlog("DecodeManager"); -DecodeManager::DecodeManager(CConnection *conn) : - conn(conn), threadException(NULL) +DecodeManager::DecodeManager(CConnection *conn_) : + conn(conn_), threadException(nullptr) { size_t cpuCount; @@ -97,8 +97,8 @@ DecodeManager::~DecodeManager() delete producerCond; delete queueMutex; - for (size_t i = 0; i < sizeof(decoders)/sizeof(decoders[0]); i++) - delete decoders[i]; + for (Decoder* decoder : decoders) + delete decoder; } bool DecodeManager::decodeRect(const Rect& r, int encoding, @@ -110,7 +110,7 @@ bool DecodeManager::decodeRect(const Rect& r, int encoding, QueueEntry *entry; - assert(pb != NULL); + assert(pb != nullptr); if (!Decoder::supported(encoding)) { vlog.error("Unknown encoding %d", encoding); @@ -247,7 +247,7 @@ void DecodeManager::setThreadException(const rdr::Exception& e) { os::AutoMutex a(queueMutex); - if (threadException != NULL) + if (threadException != nullptr) return; threadException = new rdr::Exception("Exception on worker thread: %s", e.str()); @@ -257,23 +257,20 @@ void DecodeManager::throwThreadException() { os::AutoMutex a(queueMutex); - if (threadException == NULL) + if (threadException == nullptr) return; rdr::Exception e(*threadException); delete threadException; - threadException = NULL; + threadException = nullptr; throw e; } -DecodeManager::DecodeThread::DecodeThread(DecodeManager* manager) +DecodeManager::DecodeThread::DecodeThread(DecodeManager* manager_) + : manager(manager_), stopRequested(false) { - this->manager = manager; - - stopRequested = false; - start(); } @@ -305,7 +302,7 @@ void DecodeManager::DecodeThread::worker() // Look for an available entry in the work queue entry = findEntry(); - if (entry == NULL) { + if (entry == nullptr) { // Wait and try again manager->consumerCond->wait(); continue; @@ -347,24 +344,15 @@ void DecodeManager::DecodeThread::worker() DecodeManager::QueueEntry* DecodeManager::DecodeThread::findEntry() { - std::list<DecodeManager::QueueEntry*>::iterator iter; Region lockedRegion; if (manager->workQueue.empty()) - return NULL; + return nullptr; if (!manager->workQueue.front()->active) return manager->workQueue.front(); - for (iter = manager->workQueue.begin(); - iter != manager->workQueue.end(); - ++iter) { - DecodeManager::QueueEntry* entry; - - std::list<DecodeManager::QueueEntry*>::iterator iter2; - - entry = *iter; - + for (DecodeManager::QueueEntry* entry : manager->workQueue) { // Another thread working on this? if (entry->active) goto next; @@ -372,8 +360,10 @@ DecodeManager::QueueEntry* DecodeManager::DecodeThread::findEntry() // If this is an ordered decoder then make sure this is the first // rectangle in the queue for that decoder if (entry->decoder->flags & DecoderOrdered) { - for (iter2 = manager->workQueue.begin(); iter2 != iter; ++iter2) { - if (entry->encoding == (*iter2)->encoding) + for (DecodeManager::QueueEntry* entry2 : manager->workQueue) { + if (entry2 == entry) + break; + if (entry->encoding == entry2->encoding) goto next; } } @@ -381,15 +371,17 @@ DecodeManager::QueueEntry* DecodeManager::DecodeThread::findEntry() // For a partially ordered decoder we must ask the decoder for each // pair of rectangles. if (entry->decoder->flags & DecoderPartiallyOrdered) { - for (iter2 = manager->workQueue.begin(); iter2 != iter; ++iter2) { - if (entry->encoding != (*iter2)->encoding) + for (DecodeManager::QueueEntry* entry2 : manager->workQueue) { + if (entry2 == entry) + break; + if (entry->encoding != entry2->encoding) continue; if (entry->decoder->doRectsConflict(entry->rect, entry->bufferStream->data(), entry->bufferStream->length(), - (*iter2)->rect, - (*iter2)->bufferStream->data(), - (*iter2)->bufferStream->length(), + entry2->rect, + entry2->bufferStream->data(), + entry2->bufferStream->length(), *entry->server)) goto next; } @@ -405,5 +397,5 @@ next: lockedRegion.assign_union(entry->affectedRegion); } - return NULL; + return nullptr; } diff --git a/common/rfb/DecodeManager.h b/common/rfb/DecodeManager.h index a8e0cac9..5435bfc1 100644 --- a/common/rfb/DecodeManager.h +++ b/common/rfb/DecodeManager.h @@ -98,7 +98,7 @@ namespace rfb { void stop(); protected: - void worker(); + void worker() override; DecodeManager::QueueEntry* findEntry(); private: diff --git a/common/rfb/Decoder.cxx b/common/rfb/Decoder.cxx index 78c54ec3..e9bc9a4f 100644 --- a/common/rfb/Decoder.cxx +++ b/common/rfb/Decoder.cxx @@ -37,7 +37,7 @@ using namespace rfb; -Decoder::Decoder(enum DecoderFlags flags) : flags(flags) +Decoder::Decoder(enum DecoderFlags flags_) : flags(flags_) { } @@ -103,6 +103,6 @@ Decoder* Decoder::createDecoder(int encoding) return new H264Decoder(); #endif default: - return NULL; + return nullptr; } } diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index c2658a70..5c1429d2 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -138,7 +138,7 @@ EncodeManager::EncodeManager(SConnection* conn_) { StatsVector::iterator iter; - encoders.resize(encoderClassMax, NULL); + encoders.resize(encoderClassMax, nullptr); activeEncoders.resize(encoderTypeMax, encoderRaw); encoders[encoderRaw] = new RawEncoder(conn); @@ -161,12 +161,10 @@ EncodeManager::EncodeManager(SConnection* conn_) EncodeManager::~EncodeManager() { - std::vector<Encoder*>::iterator iter; - logStats(); - for (iter = encoders.begin();iter != encoders.end();iter++) - delete *iter; + for (Encoder* encoder : encoders) + delete encoder; } void EncodeManager::logStats() @@ -332,7 +330,7 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, * We need to render the cursor seperately as it has its own * magical pixel buffer, so split it out from the changed region. */ - if (renderedCursor != NULL) { + if (renderedCursor != nullptr) { cursorRegion = changed.intersect(renderedCursor->getEffectiveRect()); changed.assign_subtract(renderedCursor->getEffectiveRect()); } diff --git a/common/rfb/EncodeManager.h b/common/rfb/EncodeManager.h index 33484db8..a01a1614 100644 --- a/common/rfb/EncodeManager.h +++ b/common/rfb/EncodeManager.h @@ -61,7 +61,7 @@ namespace rfb { size_t maxUpdateSize); protected: - virtual void handleTimeout(Timer* t); + void handleTimeout(Timer* t) override; void doUpdate(bool allowLossy, const Region& changed, const Region& copied, const Point& copy_delta, @@ -142,7 +142,7 @@ namespace rfb { const uint8_t* data_, int stride); private: - virtual uint8_t* getBufferRW(const Rect& r, int* stride); + uint8_t* getBufferRW(const Rect& r, int* stride) override; }; OffsetPixelBuffer offsetPixelBuffer; diff --git a/common/rfb/H264Decoder.cxx b/common/rfb/H264Decoder.cxx index f18554ef..53b223db 100644 --- a/common/rfb/H264Decoder.cxx +++ b/common/rfb/H264Decoder.cxx @@ -51,18 +51,18 @@ H264Decoder::~H264Decoder() void H264Decoder::resetContexts() { os::AutoMutex lock(&mutex); - for (std::deque<H264DecoderContext*>::iterator it = contexts.begin(); it != contexts.end(); it++) - delete *it; + for (H264DecoderContext* context : contexts) + delete context; contexts.clear(); } H264DecoderContext* H264Decoder::findContext(const Rect& r) { os::AutoMutex m(&mutex); - for (std::deque<H264DecoderContext*>::iterator it = contexts.begin(); it != contexts.end(); it++) - if ((*it)->isEqualRect(r)) - return *it; - return NULL; + for (H264DecoderContext* context : contexts) + if (context->isEqualRect(r)) + return context; + return nullptr; } bool H264Decoder::readRect(const Rect& /*r*/, @@ -79,9 +79,9 @@ bool H264Decoder::readRect(const Rect& /*r*/, len = is->readU32(); os->writeU32(len); - uint32_t flags = is->readU32(); + uint32_t reset = is->readU32(); - os->writeU32(flags); + os->writeU32(reset); if (!is->hasDataOrRestore(len)) return false; @@ -100,15 +100,15 @@ void H264Decoder::decodeRect(const Rect& r, const uint8_t* buffer, { rdr::MemInStream is(buffer, buflen); uint32_t len = is.readU32(); - uint32_t flags = is.readU32(); + uint32_t reset = is.readU32(); - H264DecoderContext* ctx = NULL; - if (flags & resetAllContexts) + H264DecoderContext* ctx = nullptr; + if (reset & resetAllContexts) { resetContexts(); if (!len) return; - flags &= ~(resetContext | resetAllContexts); + reset &= ~(resetContext | resetAllContexts); } else { ctx = findContext(r); } diff --git a/common/rfb/H264Decoder.h b/common/rfb/H264Decoder.h index b4f5553e..8ba47799 100644 --- a/common/rfb/H264Decoder.h +++ b/common/rfb/H264Decoder.h @@ -33,11 +33,12 @@ namespace rfb { public: H264Decoder(); virtual ~H264Decoder(); - virtual bool readRect(const Rect& r, rdr::InStream* is, - const ServerParams& server, rdr::OutStream* os); - virtual void decodeRect(const Rect& r, const uint8_t* buffer, - size_t buflen, const ServerParams& server, - ModifiablePixelBuffer* pb); + bool readRect(const Rect& r, rdr::InStream* is, + const ServerParams& server, + rdr::OutStream* os) override; + void decodeRect(const Rect& r, const uint8_t* buffer, + size_t buflen, const ServerParams& server, + ModifiablePixelBuffer* pb) override; private: void resetContexts(); diff --git a/common/rfb/H264LibavDecoderContext.cxx b/common/rfb/H264LibavDecoderContext.cxx index 8697a5a5..5bd1dbbf 100644 --- a/common/rfb/H264LibavDecoderContext.cxx +++ b/common/rfb/H264LibavDecoderContext.cxx @@ -42,9 +42,9 @@ static LogWriter vlog("H264LibavDecoderContext"); bool H264LibavDecoderContext::initCodec() { os::AutoMutex lock(&mutex); - sws = NULL; - swsBuffer = NULL; - h264WorkBuffer = NULL; + sws = nullptr; + swsBuffer = nullptr; + h264WorkBuffer = nullptr; h264WorkBufferLength = 0; const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264); @@ -78,7 +78,7 @@ bool H264LibavDecoderContext::initCodec() { return false; } - if (avcodec_open2(avctx, codec, NULL) < 0) + if (avcodec_open2(avctx, codec, nullptr) < 0) { av_parser_close(parser); avcodec_free_context(&avctx); @@ -117,7 +117,7 @@ uint8_t* H264LibavDecoderContext::makeH264WorkBuffer(const uint8_t* buffer, uint if (!h264WorkBuffer || reserve_len > h264WorkBufferLength) { h264WorkBuffer = (uint8_t*)realloc(h264WorkBuffer, reserve_len); - if (h264WorkBuffer == NULL) { + if (h264WorkBuffer == nullptr) { throw Exception("H264LibavDecoderContext: Unable to allocate memory"); } h264WorkBufferLength = reserve_len; @@ -204,7 +204,7 @@ void H264LibavDecoderContext::decode(const uint8_t* h264_in_buffer, #ifdef FFMPEG_INIT_PACKET_DEPRECATED packet->size = 0; - packet->data = NULL; + packet->data = nullptr; av_packet_free(&packet); #else delete packet; @@ -218,7 +218,7 @@ void H264LibavDecoderContext::decode(const uint8_t* h264_in_buffer, sws = sws_getCachedContext(sws, frame->width, frame->height, avctx->pix_fmt, frame->width, frame->height, AV_PIX_FMT_RGB32, - 0, NULL, NULL, NULL); + 0, nullptr, nullptr, nullptr); int stride; pb->getBuffer(rect, &stride); diff --git a/common/rfb/H264LibavDecoderContext.h b/common/rfb/H264LibavDecoderContext.h index 148ba1ad..f399b3cc 100644 --- a/common/rfb/H264LibavDecoderContext.h +++ b/common/rfb/H264LibavDecoderContext.h @@ -34,12 +34,12 @@ namespace rfb { H264LibavDecoderContext(const Rect &r) : H264DecoderContext(r) {} ~H264LibavDecoderContext() { freeCodec(); } - virtual void decode(const uint8_t* h264_buffer, uint32_t len, - ModifiablePixelBuffer* pb); + void decode(const uint8_t* h264_buffer, uint32_t len, + ModifiablePixelBuffer* pb) override; protected: - virtual bool initCodec(); - virtual void freeCodec(); + bool initCodec() override; + void freeCodec() override; private: uint8_t* makeH264WorkBuffer(const uint8_t* buffer, uint32_t len); diff --git a/common/rfb/H264WinDecoderContext.cxx b/common/rfb/H264WinDecoderContext.cxx index bb29edb6..8422b5c4 100644 --- a/common/rfb/H264WinDecoderContext.cxx +++ b/common/rfb/H264WinDecoderContext.cxx @@ -21,7 +21,7 @@ #include <mfapi.h> #include <mferror.h> #include <wmcodecdsp.h> -#define SAFE_RELEASE(obj) if (obj) { obj->Release(); obj = NULL; } +#define SAFE_RELEASE(obj) if (obj) { obj->Release(); obj = nullptr; } #include <os/Mutex.h> #include <rfb/LogWriter.h> @@ -32,6 +32,11 @@ using namespace rfb; static LogWriter vlog("H264WinDecoderContext"); +// Older MinGW lacks this definition +#ifndef HAVE_VIDEO_PROCESSOR_MFT +static GUID CLSID_VideoProcessorMFT = { 0x88753b26, 0x5b24, 0x49bd, { 0xb2, 0xe7, 0xc, 0x44, 0x5c, 0x78, 0xc9, 0x82 } }; +#endif + bool H264WinDecoderContext::initCodec() { os::AutoMutex lock(&mutex); @@ -41,17 +46,16 @@ bool H264WinDecoderContext::initCodec() { return false; } - if (FAILED(CoCreateInstance(CLSID_CMSH264DecoderMFT, NULL, CLSCTX_INPROC_SERVER, IID_IMFTransform, (LPVOID*)&decoder))) + if (FAILED(CoCreateInstance(CLSID_CMSH264DecoderMFT, nullptr, CLSCTX_INPROC_SERVER, IID_IMFTransform, (LPVOID*)&decoder))) { vlog.error("MediaFoundation H264 codec not found"); return false; } - GUID CLSID_VideoProcessorMFT = { 0x88753b26, 0x5b24, 0x49bd, { 0xb2, 0xe7, 0xc, 0x44, 0x5c, 0x78, 0xc9, 0x82 } }; - if (FAILED(CoCreateInstance(CLSID_VideoProcessorMFT, NULL, CLSCTX_INPROC_SERVER, IID_IMFTransform, (LPVOID*)&converter))) + if (FAILED(CoCreateInstance(CLSID_VideoProcessorMFT, nullptr, CLSCTX_INPROC_SERVER, IID_IMFTransform, (LPVOID*)&converter))) { vlog.error("Cannot create MediaFoundation Video Processor (available only on Windows 8+). Trying ColorConvert DMO."); - if (FAILED(CoCreateInstance(CLSID_CColorConvertDMO, NULL, CLSCTX_INPROC_SERVER, IID_IMFTransform, (LPVOID*)&converter))) + if (FAILED(CoCreateInstance(CLSID_CColorConvertDMO, nullptr, CLSCTX_INPROC_SERVER, IID_IMFTransform, (LPVOID*)&converter))) { decoder->Release(); vlog.error("ColorConvert DMO not found"); @@ -87,7 +91,7 @@ bool H264WinDecoderContext::initCodec() { // set decoder output type (NV12) DWORD output_index = 0; - IMFMediaType* output_type = NULL; + IMFMediaType* output_type = nullptr; while (SUCCEEDED(decoder->GetOutputAvailableType(0, output_index++, &output_type))) { GUID subtype; @@ -175,7 +179,7 @@ void H264WinDecoderContext::decode(const uint8_t* h264_buffer, } BYTE* locked; - input_buffer->Lock(&locked, NULL, NULL); + input_buffer->Lock(&locked, nullptr, nullptr); memcpy(locked, h264_buffer, len); input_buffer->Unlock(); @@ -203,7 +207,7 @@ void H264WinDecoderContext::decode(const uint8_t* h264_buffer, decoded_data.dwStreamID = 0; decoded_data.pSample = decoded_sample; decoded_data.dwStatus = 0; - decoded_data.pEvents = NULL; + decoded_data.pEvents = nullptr; DWORD status; HRESULT hr = decoder->ProcessOutput(0, 1, &decoded_data, &status); @@ -232,7 +236,7 @@ void H264WinDecoderContext::decode(const uint8_t* h264_buffer, // need to setup output type and try decoding again DWORD output_index = 0; - IMFMediaType* output_type = NULL; + IMFMediaType* output_type = nullptr; while (SUCCEEDED(decoder->GetOutputAvailableType(0, output_index++, &output_type))) { GUID subtype; @@ -242,7 +246,7 @@ void H264WinDecoderContext::decode(const uint8_t* h264_buffer, break; } output_type->Release(); - output_type = NULL; + output_type = nullptr; } // reinitialize output type (NV12) that now has correct properties (width/height/framerate) @@ -327,7 +331,7 @@ void H264WinDecoderContext::decode(const uint8_t* h264_buffer, converted_data.dwStreamID = 0; converted_data.pSample = converted_sample; converted_data.dwStatus = 0; - converted_data.pEvents = NULL; + converted_data.pEvents = nullptr; DWORD status; HRESULT hr = converter->ProcessOutput(0, 1, &converted_data, &status); @@ -342,8 +346,8 @@ void H264WinDecoderContext::decode(const uint8_t* h264_buffer, vlog.debug("Frame converted to RGB"); BYTE* out; - DWORD len; - converted_buffer->Lock(&out, NULL, &len); + DWORD buflen; + converted_buffer->Lock(&out, nullptr, &buflen); pb->imageRect(rect, out + offset_y * stride + offset_x * 4, (int)stride / 4); converted_buffer->Unlock(); } @@ -359,20 +363,20 @@ void H264WinDecoderContext::ParseSPS(const uint8_t* buffer, int length) if (available == 0) \ { \ if (length == 0) return; \ - byte = *buffer++; \ + byte_ = *buffer++; \ length--; \ available = 8; \ } \ - bit = (byte >> --available) & 1; \ + bit = (byte_ >> --available) & 1; \ } while (0) #define GET_BITS(n, var) do { \ var = 0; \ - for (int i = n-1; i >= 0; i--) \ + for (int b = n-1; b >= 0; b--) \ { \ unsigned bit; \ GET_BIT(bit); \ - var |= bit << i; \ + var |= bit << b; \ } \ } while (0) @@ -411,7 +415,7 @@ void H264WinDecoderContext::ParseSPS(const uint8_t* buffer, int length) length--; int available = 0; - uint8_t byte = 0; + uint8_t byte_ = 0; unsigned profile_idc; unsigned seq_parameter_set_id; diff --git a/common/rfb/H264WinDecoderContext.h b/common/rfb/H264WinDecoderContext.h index de51576c..92041781 100644 --- a/common/rfb/H264WinDecoderContext.h +++ b/common/rfb/H264WinDecoderContext.h @@ -33,12 +33,12 @@ namespace rfb { H264WinDecoderContext(const Rect &r) : H264DecoderContext(r) {}; ~H264WinDecoderContext() { freeCodec(); } - virtual void decode(const uint8_t* h264_buffer, uint32_t len, - ModifiablePixelBuffer* pb); + void decode(const uint8_t* h264_buffer, uint32_t len, + ModifiablePixelBuffer* pb) override; protected: - virtual bool initCodec(); - virtual void freeCodec(); + bool initCodec() override; + void freeCodec() override; private: LONG stride; @@ -48,14 +48,14 @@ namespace rfb { uint32_t crop_height = 0; uint32_t offset_x = 0; uint32_t offset_y = 0; - IMFTransform *decoder = NULL; - IMFTransform *converter = NULL; - IMFSample *input_sample = NULL; - IMFSample *decoded_sample = NULL; - IMFSample *converted_sample = NULL; - IMFMediaBuffer *input_buffer = NULL; - IMFMediaBuffer *decoded_buffer = NULL; - IMFMediaBuffer *converted_buffer = NULL; + IMFTransform *decoder = nullptr; + IMFTransform *converter = nullptr; + IMFSample *input_sample = nullptr; + IMFSample *decoded_sample = nullptr; + IMFSample *converted_sample = nullptr; + IMFMediaBuffer *input_buffer = nullptr; + IMFMediaBuffer *decoded_buffer = nullptr; + IMFMediaBuffer *converted_buffer = nullptr; void ParseSPS(const uint8_t* buffer, int length); }; diff --git a/common/rfb/HextileDecoder.cxx b/common/rfb/HextileDecoder.cxx index 2243d67f..dc9b9be7 100644 --- a/common/rfb/HextileDecoder.cxx +++ b/common/rfb/HextileDecoder.cxx @@ -191,10 +191,10 @@ void HextileDecoder::hextileDecode(const Rect& r, rdr::InStream* is, if (x + w > 16 || y + h > 16) { throw rfb::Exception("HEXTILE_DECODE: Hextile out of bounds"); } - T* ptr = buf + y * t.width() + x; + ptr = buf + y * t.width() + x; int rowAdd = t.width() - w; while (h-- > 0) { - int len = w; + len = w; while (len-- > 0) *ptr++ = fg; ptr += rowAdd; } diff --git a/common/rfb/HextileDecoder.h b/common/rfb/HextileDecoder.h index 9163b5bb..38e8b776 100644 --- a/common/rfb/HextileDecoder.h +++ b/common/rfb/HextileDecoder.h @@ -29,11 +29,12 @@ namespace rfb { public: HextileDecoder(); virtual ~HextileDecoder(); - virtual bool readRect(const Rect& r, rdr::InStream* is, - const ServerParams& server, rdr::OutStream* os); - virtual void decodeRect(const Rect& r, const uint8_t* buffer, - size_t buflen, const ServerParams& server, - ModifiablePixelBuffer* pb); + bool readRect(const Rect& r, rdr::InStream* is, + const ServerParams& server, + rdr::OutStream* os) override; + void decodeRect(const Rect& r, const uint8_t* buffer, + size_t buflen, const ServerParams& server, + ModifiablePixelBuffer* pb) override; private: template<class T> inline T readPixel(rdr::InStream* is); diff --git a/common/rfb/HextileEncoder.cxx b/common/rfb/HextileEncoder.cxx index a63cf1fb..0666d02d 100644 --- a/common/rfb/HextileEncoder.cxx +++ b/common/rfb/HextileEncoder.cxx @@ -38,8 +38,8 @@ BoolParameter improvedHextile("ImprovedHextile", "ratios by the cost of using more CPU time", true); -HextileEncoder::HextileEncoder(SConnection* conn) : - Encoder(conn, encodingHextile, EncoderPlain) +HextileEncoder::HextileEncoder(SConnection* conn_) : + Encoder(conn_, encodingHextile, EncoderPlain) { } @@ -365,7 +365,7 @@ class HextileTile { template<class T> HextileTile<T>::HextileTile() - : m_tile(NULL), m_width(0), m_height(0), + : m_tile(nullptr), m_width(0), m_height(0), m_size(0), m_flags(0), m_background(0), m_foreground(0), m_numSubrects(0) { diff --git a/common/rfb/HextileEncoder.h b/common/rfb/HextileEncoder.h index 20721b7c..55f0508d 100644 --- a/common/rfb/HextileEncoder.h +++ b/common/rfb/HextileEncoder.h @@ -27,11 +27,11 @@ namespace rfb { public: HextileEncoder(SConnection* conn); virtual ~HextileEncoder(); - virtual bool isSupported(); - virtual void writeRect(const PixelBuffer* pb, const Palette& palette); - virtual void writeSolidRect(int width, int height, - const PixelFormat& pf, - const uint8_t* colour); + bool isSupported() override; + void writeRect(const PixelBuffer* pb, + const Palette& palette) override; + void writeSolidRect(int width, int height, const PixelFormat& pf, + const uint8_t* colour) override; private: template<class T> inline void writePixel(rdr::OutStream* os, T pixel); diff --git a/common/rfb/Hostname.h b/common/rfb/Hostname.h index 1971e343..a09cca3f 100644 --- a/common/rfb/Hostname.h +++ b/common/rfb/Hostname.h @@ -29,7 +29,7 @@ namespace rfb { static bool isAllSpace(const char *string) { - if (string == NULL) + if (string == nullptr) return false; while(*string != '\0') { if (! isspace(*string)) @@ -46,7 +46,7 @@ namespace rfb { const char* hostEnd; const char* portStart; - if (hi == NULL) + if (hi == nullptr) throw rdr::Exception("NULL host specified"); // Trim leading whitespace @@ -59,19 +59,19 @@ namespace rfb { if (hi[0] == '[') { hostStart = &hi[1]; hostEnd = strchr(hostStart, ']'); - if (hostEnd == NULL) + if (hostEnd == nullptr) throw rdr::Exception("unmatched [ in host"); portStart = hostEnd + 1; if (isAllSpace(portStart)) - portStart = NULL; + portStart = nullptr; } else { hostStart = &hi[0]; hostEnd = strrchr(hostStart, ':'); - if (hostEnd == NULL) { + if (hostEnd == nullptr) { hostEnd = hostStart + strlen(hostStart); - portStart = NULL; + portStart = nullptr; } else { if ((hostEnd > hostStart) && (hostEnd[-1] == ':')) hostEnd--; @@ -79,7 +79,7 @@ namespace rfb { if (portStart != hostEnd) { // We found more : in the host. This is probably an IPv6 address hostEnd = hostStart + strlen(hostStart); - portStart = NULL; + portStart = nullptr; } } } @@ -93,7 +93,7 @@ namespace rfb { else *host = std::string(hostStart, hostEnd - hostStart); - if (portStart == NULL) + if (portStart == nullptr) *port = basePort; else { char* end; diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx index a4dd5f39..42d5c475 100644 --- a/common/rfb/JpegCompressor.cxx +++ b/common/rfb/JpegCompressor.cxx @@ -162,9 +162,9 @@ void JpegCompressor::compress(const uint8_t *buf, volatile int stride, int w = r.width(); int h = r.height(); int pixelsize; - uint8_t * volatile srcBuf = NULL; + uint8_t * volatile srcBuf = nullptr; volatile bool srcBufIsTemp = false; - JSAMPROW * volatile rowPointer = NULL; + JSAMPROW * volatile rowPointer = nullptr; if(setjmp(err->jmpBuffer)) { // this will execute if libjpeg has an error diff --git a/common/rfb/JpegDecompressor.cxx b/common/rfb/JpegDecompressor.cxx index 44c54fb2..92ef014f 100644 --- a/common/rfb/JpegDecompressor.cxx +++ b/common/rfb/JpegDecompressor.cxx @@ -159,9 +159,9 @@ void JpegDecompressor::decompress(const uint8_t *jpegBuf, int h = r.height(); int pixelsize; int dstBufStride; - uint8_t * volatile dstBuf = NULL; + uint8_t * volatile dstBuf = nullptr; volatile bool dstBufIsTemp = false; - JSAMPROW * volatile rowPointer = NULL; + JSAMPROW * volatile rowPointer = nullptr; if(setjmp(err->jmpBuffer)) { // this will execute if libjpeg has an error diff --git a/common/rfb/KeyRemapper.cxx b/common/rfb/KeyRemapper.cxx index 762eb413..328955d7 100644 --- a/common/rfb/KeyRemapper.cxx +++ b/common/rfb/KeyRemapper.cxx @@ -89,7 +89,7 @@ public: : StringParameter("RemapKeys", "Comma-separated list of incoming keysyms to remap. Mappings are expressed as two hex values, prefixed by 0x, and separated by ->", "") { KeyRemapper::defInstance.setMapping(""); } - bool setParam(const char* v) { + bool setParam(const char* v) override { KeyRemapper::defInstance.setMapping(v); return StringParameter::setParam(v); } diff --git a/common/rfb/LogWriter.cxx b/common/rfb/LogWriter.cxx index dc9db9d1..b222d268 100644 --- a/common/rfb/LogWriter.cxx +++ b/common/rfb/LogWriter.cxx @@ -34,7 +34,8 @@ rfb::LogParameter rfb::logParams; using namespace rfb; -LogWriter::LogWriter(const char* name) : m_name(name), m_level(0), m_log(0), m_next(log_writers) { +LogWriter::LogWriter(const char* name) + : m_name(name), m_level(0), m_log(nullptr), m_next(log_writers) { log_writers = this; } @@ -72,7 +73,7 @@ LogWriter::getLogWriter(const char* name) { if (strcasecmp(name, current->m_name) == 0) return current; current = current->m_next; } - return 0; + return nullptr; } bool LogWriter::setLogParams(const char* params) { @@ -83,7 +84,7 @@ bool LogWriter::setLogParams(const char* params) { return false; } int level = atoi(parts[2].c_str()); - Logger* logger = 0; + Logger* logger = nullptr; if (!parts[1].empty()) { logger = Logger::getLogger(parts[1].c_str()); if (!logger) diff --git a/common/rfb/LogWriter.h b/common/rfb/LogWriter.h index 6eff6da1..d1fd4990 100644 --- a/common/rfb/LogWriter.h +++ b/common/rfb/LogWriter.h @@ -104,7 +104,7 @@ namespace rfb { class LogParameter : public StringParameter { public: LogParameter(); - virtual bool setParam(const char* v); + bool setParam(const char* v) override; }; extern LogParameter logParams; diff --git a/common/rfb/Logger.cxx b/common/rfb/Logger.cxx index 7e0895e4..25f7ccb7 100644 --- a/common/rfb/Logger.cxx +++ b/common/rfb/Logger.cxx @@ -31,9 +31,11 @@ using namespace rfb; -Logger* Logger::loggers = 0; +Logger* Logger::loggers = nullptr; -Logger::Logger(const char* name) : registered(false), m_name(name), m_next(0) { +Logger::Logger(const char* name) + : registered(false), m_name(name), m_next(nullptr) +{ } Logger::~Logger() { @@ -78,7 +80,7 @@ Logger::getLogger(const char* name) { if (strcasecmp(name, current->m_name) == 0) return current; current = current->m_next; } - return 0; + return nullptr; } void diff --git a/common/rfb/Logger_file.cxx b/common/rfb/Logger_file.cxx index 099a3501..eabe420a 100644 --- a/common/rfb/Logger_file.cxx +++ b/common/rfb/Logger_file.cxx @@ -33,7 +33,7 @@ using namespace rfb; Logger_File::Logger_File(const char* loggerName) - : Logger(loggerName), indent(13), width(79), m_file(0), + : Logger(loggerName), indent(13), width(79), m_file(nullptr), m_lastLogTime(0) { m_filename[0] = '\0'; @@ -65,7 +65,7 @@ void Logger_File::write(int /*level*/, const char *logname, const char *message) if (!m_file) return; } - time_t current = time(0); + time_t current = time(nullptr); if (current != m_lastLogTime) { m_lastLogTime = current; fprintf(m_file, "\n%s", ctime(&m_lastLogTime)); @@ -115,7 +115,7 @@ void Logger_File::closeFile() { if (m_file) { fclose(m_file); - m_file = 0; + m_file = nullptr; } } diff --git a/common/rfb/Logger_file.h b/common/rfb/Logger_file.h index 4542d23c..6f2a4ef6 100644 --- a/common/rfb/Logger_file.h +++ b/common/rfb/Logger_file.h @@ -35,7 +35,7 @@ namespace rfb { Logger_File(const char* loggerName); ~Logger_File(); - virtual void write(int level, const char *logname, const char *message); + void write(int level, const char *logname, const char *message) override; void setFilename(const char* filename); void setFile(FILE* file); diff --git a/common/rfb/Logger_syslog.cxx b/common/rfb/Logger_syslog.cxx index 320ab4b0..de9e425e 100644 --- a/common/rfb/Logger_syslog.cxx +++ b/common/rfb/Logger_syslog.cxx @@ -35,7 +35,7 @@ using namespace rfb; Logger_Syslog::Logger_Syslog(const char* loggerName) : Logger(loggerName) { - openlog(0, LOG_CONS | LOG_PID, LOG_USER); + openlog(nullptr, LOG_CONS | LOG_PID, LOG_USER); } Logger_Syslog::~Logger_Syslog() diff --git a/common/rfb/Logger_syslog.h b/common/rfb/Logger_syslog.h index cf987281..20c46a5f 100644 --- a/common/rfb/Logger_syslog.h +++ b/common/rfb/Logger_syslog.h @@ -31,7 +31,7 @@ namespace rfb { Logger_Syslog(const char* loggerName); virtual ~Logger_Syslog(); - virtual void write(int level, const char *logname, const char *message); + void write(int level, const char *logname, const char *message) override; }; void initSyslogLogger(); diff --git a/common/rfb/Palette.h b/common/rfb/Palette.h index 6b8cc57e..d22af0dc 100644 --- a/common/rfb/Palette.h +++ b/common/rfb/Palette.h @@ -75,10 +75,10 @@ inline bool rfb::Palette::insert(uint32_t colour, int numPixels) hash_key = genHash(colour); pnode = hash[hash_key]; - prev_pnode = NULL; + prev_pnode = nullptr; // Do we already have an entry for this colour? - while (pnode != NULL) { + while (pnode != nullptr) { if (pnode->colour == colour) { // Yup @@ -114,12 +114,12 @@ inline bool rfb::Palette::insert(uint32_t colour, int numPixels) // Create a new colour entry pnode = &list[numColours]; - pnode->next = NULL; + pnode->next = nullptr; pnode->idx = 0; pnode->colour = colour; // Add it to the hash table - if (prev_pnode != NULL) + if (prev_pnode != nullptr) prev_pnode->next = pnode; else hash[hash_key] = pnode; @@ -152,7 +152,7 @@ inline unsigned char rfb::Palette::lookup(uint32_t colour) const hash_key = genHash(colour); pnode = hash[hash_key]; - while (pnode != NULL) { + while (pnode != nullptr) { if (pnode->colour == colour) return pnode->idx; pnode = pnode->next; diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index c8b5f3d7..f1354a43 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -326,7 +326,7 @@ FullFramePixelBuffer::FullFramePixelBuffer(const PixelFormat& pf, int w, int h, { } -FullFramePixelBuffer::FullFramePixelBuffer() : data(0) {} +FullFramePixelBuffer::FullFramePixelBuffer() : data(nullptr) {} FullFramePixelBuffer::~FullFramePixelBuffer() {} @@ -365,7 +365,7 @@ void FullFramePixelBuffer::setBuffer(int width, int height, throw rfb::Exception("Invalid PixelBuffer height of %d pixels requested", height); if ((stride_ < 0) || (stride_ > maxPixelBufferStride) || (stride_ < width)) throw rfb::Exception("Invalid PixelBuffer stride of %d pixels requested", stride_); - if ((width != 0) && (height != 0) && (data_ == NULL)) + if ((width != 0) && (height != 0) && (data_ == nullptr)) throw rfb::Exception("PixelBuffer requested without a valid memory area"); ModifiablePixelBuffer::setSize(width, height); @@ -383,12 +383,12 @@ void FullFramePixelBuffer::setSize(int /*w*/, int /*h*/) // Automatically allocates enough space for the specified format & area ManagedPixelBuffer::ManagedPixelBuffer() - : data_(NULL), datasize(0) + : data_(nullptr), datasize(0) { } ManagedPixelBuffer::ManagedPixelBuffer(const PixelFormat& pf, int w, int h) - : FullFramePixelBuffer(pf, 0, 0, NULL, 0), data_(NULL), datasize(0) + : FullFramePixelBuffer(pf, 0, 0, nullptr, 0), data_(nullptr), datasize(0) { setSize(w, h); } @@ -413,7 +413,7 @@ void ManagedPixelBuffer::setSize(int w, int h) if (datasize < new_datasize) { if (data_) { delete [] data_; - data_ = NULL; + data_ = nullptr; datasize = 0; } if (new_datasize) { diff --git a/common/rfb/PixelBuffer.h b/common/rfb/PixelBuffer.h index 33a9c7ae..963fbbf6 100644 --- a/common/rfb/PixelBuffer.h +++ b/common/rfb/PixelBuffer.h @@ -151,16 +151,16 @@ namespace rfb { virtual ~FullFramePixelBuffer(); public: - virtual const uint8_t* getBuffer(const Rect& r, int* stride) const; - virtual uint8_t* getBufferRW(const Rect& r, int* stride); - virtual void commitBufferRW(const Rect& r); + const uint8_t* getBuffer(const Rect& r, int* stride) const override; + uint8_t* getBufferRW(const Rect& r, int* stride) override; + void commitBufferRW(const Rect& r) override; protected: FullFramePixelBuffer(); virtual void setBuffer(int width, int height, uint8_t* data, int stride); private: - virtual void setSize(int w, int h); + void setSize(int w, int h) override; private: uint8_t* data; @@ -178,7 +178,7 @@ namespace rfb { // Manage the pixel buffer layout virtual void setPF(const PixelFormat &pf); - virtual void setSize(int w, int h); + void setSize(int w, int h) override; private: uint8_t* data_; // Mirrors FullFramePixelBuffer::data diff --git a/common/rfb/RREDecoder.h b/common/rfb/RREDecoder.h index a1d7f9b8..8490146c 100644 --- a/common/rfb/RREDecoder.h +++ b/common/rfb/RREDecoder.h @@ -29,11 +29,12 @@ namespace rfb { public: RREDecoder(); virtual ~RREDecoder(); - virtual bool readRect(const Rect& r, rdr::InStream* is, - const ServerParams& server, rdr::OutStream* os); - virtual void decodeRect(const Rect& r, const uint8_t* buffer, - size_t buflen, const ServerParams& server, - ModifiablePixelBuffer* pb); + bool readRect(const Rect& r, rdr::InStream* is, + const ServerParams& server, + rdr::OutStream* os) override; + void decodeRect(const Rect& r, const uint8_t* buffer, + size_t buflen, const ServerParams& server, + ModifiablePixelBuffer* pb) override; private: template<class T> inline T readPixel(rdr::InStream* is); diff --git a/common/rfb/RREEncoder.cxx b/common/rfb/RREEncoder.cxx index e73a23bf..f3e3b68a 100644 --- a/common/rfb/RREEncoder.cxx +++ b/common/rfb/RREEncoder.cxx @@ -31,8 +31,8 @@ using namespace rfb; -RREEncoder::RREEncoder(SConnection* conn) : - Encoder(conn, encodingRRE, EncoderPlain) +RREEncoder::RREEncoder(SConnection* conn_) : + Encoder(conn_, encodingRRE, EncoderPlain) { } diff --git a/common/rfb/RREEncoder.h b/common/rfb/RREEncoder.h index b13135b4..e21586ec 100644 --- a/common/rfb/RREEncoder.h +++ b/common/rfb/RREEncoder.h @@ -29,11 +29,11 @@ namespace rfb { public: RREEncoder(SConnection* conn); virtual ~RREEncoder(); - virtual bool isSupported(); - virtual void writeRect(const PixelBuffer* pb, const Palette& palette); - virtual void writeSolidRect(int width, int height, - const PixelFormat& pf, - const uint8_t* colour); + bool isSupported() override; + void writeRect(const PixelBuffer* pb, + const Palette& palette) override; + void writeSolidRect(int width, int height, const PixelFormat& pf, + const uint8_t* colour) override; private: template<class T> inline void writePixel(rdr::OutStream* os, T pixel); diff --git a/common/rfb/RawDecoder.h b/common/rfb/RawDecoder.h index 33948ced..2ac8b0bd 100644 --- a/common/rfb/RawDecoder.h +++ b/common/rfb/RawDecoder.h @@ -25,11 +25,12 @@ namespace rfb { public: RawDecoder(); virtual ~RawDecoder(); - virtual bool readRect(const Rect& r, rdr::InStream* is, - const ServerParams& server, rdr::OutStream* os); - virtual void decodeRect(const Rect& r, const uint8_t* buffer, - size_t buflen, const ServerParams& server, - ModifiablePixelBuffer* pb); + bool readRect(const Rect& r, rdr::InStream* is, + const ServerParams& server, + rdr::OutStream* os) override; + void decodeRect(const Rect& r, const uint8_t* buffer, + size_t buflen, const ServerParams& server, + ModifiablePixelBuffer* pb) override; }; } #endif diff --git a/common/rfb/RawEncoder.cxx b/common/rfb/RawEncoder.cxx index 2fa1af36..eff8999d 100644 --- a/common/rfb/RawEncoder.cxx +++ b/common/rfb/RawEncoder.cxx @@ -29,8 +29,8 @@ using namespace rfb; -RawEncoder::RawEncoder(SConnection* conn) : - Encoder(conn, encodingRaw, EncoderPlain) +RawEncoder::RawEncoder(SConnection* conn_) : + Encoder(conn_, encodingRaw, EncoderPlain) { } diff --git a/common/rfb/RawEncoder.h b/common/rfb/RawEncoder.h index 76da4c5b..e191645c 100644 --- a/common/rfb/RawEncoder.h +++ b/common/rfb/RawEncoder.h @@ -27,11 +27,11 @@ namespace rfb { public: RawEncoder(SConnection* conn); virtual ~RawEncoder(); - virtual bool isSupported(); - virtual void writeRect(const PixelBuffer* pb, const Palette& palette); - virtual void writeSolidRect(int width, int height, - const PixelFormat& pf, - const uint8_t* colour); + bool isSupported() override; + void writeRect(const PixelBuffer* pb, + const Palette& palette) override; + void writeSolidRect(int width, int height, const PixelFormat& pf, + const uint8_t* colour) override; }; } #endif diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index 12ba0f1a..866d19a2 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -23,6 +23,9 @@ #include <stdio.h> #include <string.h> + +#include <algorithm> + #include <rfb/Exception.h> #include <rfb/Security.h> #include <rfb/clipboardTypes.h> @@ -43,12 +46,12 @@ using namespace rfb; static LogWriter vlog("SConnection"); -SConnection::SConnection(AccessRights accessRights) - : readyForSetColourMapEntries(false), - is(0), os(0), reader_(0), writer_(0), ssecurity(0), +SConnection::SConnection(AccessRights accessRights_) + : readyForSetColourMapEntries(false), is(nullptr), os(nullptr), + reader_(nullptr), writer_(nullptr), ssecurity(nullptr), authFailureTimer(this, &SConnection::handleAuthFailureTimeout), state_(RFBSTATE_UNINITIALISED), preferredEncoding(encodingRaw), - accessRights(accessRights), hasRemoteClipboard(false), + accessRights(accessRights_), hasRemoteClipboard(false), hasLocalClipboard(false), unsolicitedClipboardAttempt(false) { @@ -206,12 +209,10 @@ void SConnection::processSecurityType(int secType) { // Verify that the requested security type should be offered std::list<uint8_t> secTypes; - std::list<uint8_t>::iterator i; secTypes = security.GetEnabledSecTypes(); - for (i=secTypes.begin(); i!=secTypes.end(); i++) - if (*i == secType) break; - if (i == secTypes.end()) + if (std::find(secTypes.begin(), secTypes.end(), + secType) == secTypes.end()) throw Exception("Requested security type not available"); vlog.info("Client requests security type %s(%d)", @@ -586,7 +587,7 @@ void SConnection::sendClipboardData(const char* data) // FIXME: This conversion magic should be in SMsgWriter std::string filtered(convertCRLF(data)); size_t sizes[1] = { filtered.size() + 1 }; - const uint8_t* data[1] = { (const uint8_t*)filtered.c_str() }; + const uint8_t* datas[1] = { (const uint8_t*)filtered.c_str() }; if (unsolicitedClipboardAttempt) { unsolicitedClipboardAttempt = false; @@ -598,7 +599,7 @@ void SConnection::sendClipboardData(const char* data) } } - writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, data); + writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, datas); } else { writer()->writeServerCutText(data); } @@ -607,11 +608,11 @@ void SConnection::sendClipboardData(const char* data) void SConnection::cleanup() { delete ssecurity; - ssecurity = NULL; + ssecurity = nullptr; delete reader_; - reader_ = NULL; + reader_ = nullptr; delete writer_; - writer_ = NULL; + writer_ = nullptr; } void SConnection::writeFakeColourMap(void) diff --git a/common/rfb/SConnection.h b/common/rfb/SConnection.h index 5bc61677..2ac53269 100644 --- a/common/rfb/SConnection.h +++ b/common/rfb/SConnection.h @@ -71,7 +71,7 @@ namespace rfb { // later, after queryConnection() has returned. It can only be called when // in state RFBSTATE_QUERYING. On rejection, an AuthFailureException is // thrown, so this must be handled appropriately by the caller. - void approveConnection(bool accept, const char* reason=0); + void approveConnection(bool accept, const char* reason=nullptr); // Methods to terminate the connection @@ -83,18 +83,17 @@ namespace rfb { // Overridden from SMsgHandler - virtual void setEncodings(int nEncodings, const int32_t* encodings); + void setEncodings(int nEncodings, const int32_t* encodings) override; - virtual void clientCutText(const char* str); + void clientCutText(const char* str) override; - virtual void handleClipboardRequest(uint32_t flags); - virtual void handleClipboardPeek(); - virtual void handleClipboardNotify(uint32_t flags); - virtual void handleClipboardProvide(uint32_t flags, - const size_t* lengths, - const uint8_t* const* data); + void handleClipboardRequest(uint32_t flags) override; + void handleClipboardPeek() override; + void handleClipboardNotify(uint32_t flags) override; + void handleClipboardProvide(uint32_t flags, const size_t* lengths, + const uint8_t* const* data) override; - virtual void supportsQEMUKeyEvent(); + void supportsQEMUKeyEvent() override; // Methods to be overridden in a derived class @@ -118,27 +117,27 @@ namespace rfb { // clientInit() is called when the ClientInit message is received. The // derived class must call on to SConnection::clientInit(). - virtual void clientInit(bool shared); + void clientInit(bool shared) override; // setPixelFormat() is called when a SetPixelFormat message is received. // The derived class must call on to SConnection::setPixelFormat(). - virtual void setPixelFormat(const PixelFormat& pf); + void setPixelFormat(const PixelFormat& pf) override; // framebufferUpdateRequest() is called when a FramebufferUpdateRequest // message is received. The derived class must call on to // SConnection::framebufferUpdateRequest(). - virtual void framebufferUpdateRequest(const Rect& r, bool incremental); + void framebufferUpdateRequest(const Rect& r, bool incremental) override; // fence() is called when we get a fence request or response. By default // it responds directly to requests (stating it doesn't support any // synchronisation) and drops responses. Override to implement more proper // support. - virtual void fence(uint32_t flags, unsigned len, const uint8_t data[]); + void fence(uint32_t flags, unsigned len, const uint8_t data[]) override; // enableContinuousUpdates() is called when the client wants to enable // or disable continuous updates, or change the active area. - virtual void enableContinuousUpdates(bool enable, - int x, int y, int w, int h); + void enableContinuousUpdates(bool enable, + int x, int y, int w, int h) override; // handleClipboardRequest() is called whenever the client requests // the server to send over its clipboard data. It will only be diff --git a/common/rfb/SDesktop.h b/common/rfb/SDesktop.h index 94e4b028..94fcaa28 100644 --- a/common/rfb/SDesktop.h +++ b/common/rfb/SDesktop.h @@ -124,14 +124,18 @@ namespace rfb { // a plain black desktop of the specified format. class SStaticDesktop : public SDesktop { public: - SStaticDesktop(const Point& size) : server(0), buffer(0) { + SStaticDesktop(const Point& size) + : server(nullptr), buffer(nullptr) + { PixelFormat pf; const uint8_t black[4] = { 0, 0, 0, 0 }; buffer = new ManagedPixelBuffer(pf, size.x, size.y); if (buffer) buffer->fillRect(buffer->getRect(), black); } - SStaticDesktop(const Point& size, const PixelFormat& pf) : buffer(0) { + SStaticDesktop(const Point& size, const PixelFormat& pf) + : buffer(nullptr) + { const uint8_t black[4] = { 0, 0, 0, 0 }; buffer = new ManagedPixelBuffer(pf, size.x, size.y); if (buffer) @@ -141,13 +145,13 @@ namespace rfb { if (buffer) delete buffer; } - virtual void init(VNCServer* vs) { + void init(VNCServer* vs) override { server = vs; server->setPixelBuffer(buffer); } - virtual void queryConnection(network::Socket* sock, - const char* /*userName*/) { - server->approveConnection(sock, true, NULL); + void queryConnection(network::Socket* sock, + const char* /*userName*/) override { + server->approveConnection(sock, true, nullptr); } protected: diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index 0792639a..9ddea53d 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -418,7 +418,7 @@ bool SMsgReader::readExtendedClipboard(int32_t len) } zis.flushUnderlying(); - zis.setUnderlying(NULL, 0); + zis.setUnderlying(nullptr, 0); handler->handleClipboardProvide(flags, lengths, buffers); diff --git a/common/rfb/SMsgWriter.cxx b/common/rfb/SMsgWriter.cxx index 8592e6f4..0c03b51d 100644 --- a/common/rfb/SMsgWriter.cxx +++ b/common/rfb/SMsgWriter.cxx @@ -93,7 +93,7 @@ void SMsgWriter::writeBell() void SMsgWriter::writeServerCutText(const char* str) { - if (strchr(str, '\r') != NULL) + if (strchr(str, '\r') != nullptr) throw Exception("Invalid carriage return in clipboard data"); std::string latin1(utf8ToLatin1(str)); @@ -508,10 +508,9 @@ void SMsgWriter::writeNoDataRects() { if (!extendedDesktopSizeMsgs.empty()) { if (client->supportsEncoding(pseudoEncodingExtendedDesktopSize)) { - std::list<ExtendedDesktopSizeMsg>::const_iterator ri; - for (ri = extendedDesktopSizeMsgs.begin();ri != extendedDesktopSizeMsgs.end();++ri) { + for (ExtendedDesktopSizeMsg msg : extendedDesktopSizeMsgs) { // FIXME: We can probably skip multiple reasonServer entries - writeExtendedDesktopSizeRect(ri->reason, ri->result, + writeExtendedDesktopSizeRect(msg.reason, msg.result, client->width(), client->height(), client->screenLayout()); } diff --git a/common/rfb/SSecurityNone.h b/common/rfb/SSecurityNone.h index f14d83a4..a10b4369 100644 --- a/common/rfb/SSecurityNone.h +++ b/common/rfb/SSecurityNone.h @@ -28,10 +28,10 @@ namespace rfb { class SSecurityNone : public SSecurity { public: - SSecurityNone(SConnection* sc) : SSecurity(sc) {} - virtual bool processMsg() { return true; } - virtual int getType() const {return secTypeNone;} - virtual const char* getUserName() const {return 0;} + SSecurityNone(SConnection* sc_) : SSecurity(sc_) {} + bool processMsg() override { return true; } + int getType() const override {return secTypeNone;} + const char* getUserName() const override {return nullptr;} }; } #endif diff --git a/common/rfb/SSecurityPlain.cxx b/common/rfb/SSecurityPlain.cxx index a100a757..73a21335 100644 --- a/common/rfb/SSecurityPlain.cxx +++ b/common/rfb/SSecurityPlain.cxx @@ -68,14 +68,14 @@ bool PasswordValidator::validUser(const char* username) return false; } -SSecurityPlain::SSecurityPlain(SConnection* sc) : SSecurity(sc) +SSecurityPlain::SSecurityPlain(SConnection* sc_) : SSecurity(sc_) { #ifdef WIN32 valid = new WinPasswdValidator(); #elif !defined(__APPLE__) valid = new UnixPasswordValidator(); #else - valid = NULL; + valid = nullptr; #endif state = 0; diff --git a/common/rfb/SSecurityPlain.h b/common/rfb/SSecurityPlain.h index 4ca72781..c0ac049b 100644 --- a/common/rfb/SSecurityPlain.h +++ b/common/rfb/SSecurityPlain.h @@ -43,9 +43,9 @@ namespace rfb { class SSecurityPlain : public SSecurity { public: SSecurityPlain(SConnection* sc); - virtual bool processMsg(); - virtual int getType() const { return secTypePlain; }; - virtual const char* getUserName() const { return username; } + bool processMsg() override; + int getType() const override { return secTypePlain; }; + const char* getUserName() const override { return username; } virtual ~SSecurityPlain() { } diff --git a/common/rfb/SSecurityRSAAES.cxx b/common/rfb/SSecurityRSAAES.cxx index cea62644..13e03b22 100644 --- a/common/rfb/SSecurityRSAAES.cxx +++ b/common/rfb/SSecurityRSAAES.cxx @@ -70,14 +70,15 @@ BoolParameter SSecurityRSAAES::requireUsername ("RequireUsername", "Require username for the RSA-AES security types", false, ConfServer); -SSecurityRSAAES::SSecurityRSAAES(SConnection* sc, uint32_t _secType, +SSecurityRSAAES::SSecurityRSAAES(SConnection* sc_, uint32_t _secType, int _keySize, bool _isAllEncrypted) - : SSecurity(sc), state(SendPublicKey), + : SSecurity(sc_), state(SendPublicKey), keySize(_keySize), isAllEncrypted(_isAllEncrypted), secType(_secType), serverKey(), clientKey(), - serverKeyN(NULL), serverKeyE(NULL), clientKeyN(NULL), clientKeyE(NULL), + serverKeyN(nullptr), serverKeyE(nullptr), + clientKeyN(nullptr), clientKeyE(nullptr), accessRights(AccessDefault), - rais(NULL), raos(NULL), rawis(NULL), rawos(NULL) + rais(nullptr), raos(nullptr), rawis(nullptr), rawos(nullptr) { assert(keySize == 128 || keySize == 256); } @@ -514,10 +515,10 @@ void SSecurityRSAAES::clearSecrets() delete[] serverKeyE; delete[] clientKeyN; delete[] clientKeyE; - serverKeyN = NULL; - serverKeyE = NULL; - clientKeyN = NULL; - clientKeyE = NULL; + serverKeyN = nullptr; + serverKeyE = nullptr; + clientKeyN = nullptr; + clientKeyE = nullptr; memset(serverRandom, 0, sizeof(serverRandom)); memset(clientRandom, 0, sizeof(clientRandom)); } diff --git a/common/rfb/SSecurityRSAAES.h b/common/rfb/SSecurityRSAAES.h index 0c4fc852..edac35c6 100644 --- a/common/rfb/SSecurityRSAAES.h +++ b/common/rfb/SSecurityRSAAES.h @@ -36,10 +36,10 @@ namespace rfb { SSecurityRSAAES(SConnection* sc, uint32_t secType, int keySize, bool isAllEncrypted); virtual ~SSecurityRSAAES(); - virtual bool processMsg(); - virtual const char* getUserName() const; - virtual int getType() const { return secType; } - virtual AccessRights getAccessRights() const + bool processMsg() override; + const char* getUserName() const override; + int getType() const override {return secType;} + AccessRights getAccessRights() const override { return accessRights; } diff --git a/common/rfb/SSecurityStack.cxx b/common/rfb/SSecurityStack.cxx index 9c0321d4..0ce6d754 100644 --- a/common/rfb/SSecurityStack.cxx +++ b/common/rfb/SSecurityStack.cxx @@ -24,9 +24,9 @@ using namespace rfb; -SSecurityStack::SSecurityStack(SConnection* sc, int Type, +SSecurityStack::SSecurityStack(SConnection* sc_, int Type, SSecurity* s0, SSecurity* s1) - : SSecurity(sc), state(0), state0(s0), state1(s1), type(Type) + : SSecurity(sc_), state(0), state0(s0), state1(s1), type(Type) { } @@ -61,7 +61,7 @@ bool SSecurityStack::processMsg() const char* SSecurityStack::getUserName() const { - const char* c = 0; + const char* c = nullptr; if (state1 && !c) c = state1->getUserName(); diff --git a/common/rfb/SSecurityStack.h b/common/rfb/SSecurityStack.h index cf7b10d0..d2949a21 100644 --- a/common/rfb/SSecurityStack.h +++ b/common/rfb/SSecurityStack.h @@ -27,12 +27,12 @@ namespace rfb { class SSecurityStack : public SSecurity { public: SSecurityStack(SConnection* sc, int Type, - SSecurity* s0 = NULL, SSecurity* s1 = NULL); + SSecurity* s0 = nullptr, SSecurity* s1 = nullptr); ~SSecurityStack(); - virtual bool processMsg(); - virtual int getType() const { return type; }; - virtual const char* getUserName() const; - virtual AccessRights getAccessRights() const; + bool processMsg() override; + int getType() const override { return type; }; + const char* getUserName() const override; + AccessRights getAccessRights() const override; protected: short state; SSecurity* state0; diff --git a/common/rfb/SSecurityTLS.cxx b/common/rfb/SSecurityTLS.cxx index 1abfd774..e2b82f89 100644 --- a/common/rfb/SSecurityTLS.cxx +++ b/common/rfb/SSecurityTLS.cxx @@ -66,13 +66,13 @@ StringParameter SSecurityTLS::X509_KeyFile static LogWriter vlog("TLS"); -SSecurityTLS::SSecurityTLS(SConnection* sc, bool _anon) - : SSecurity(sc), session(NULL), anon_cred(NULL), - cert_cred(NULL), anon(_anon), tlsis(NULL), tlsos(NULL), - rawis(NULL), rawos(NULL) +SSecurityTLS::SSecurityTLS(SConnection* sc_, bool _anon) + : SSecurity(sc_), session(nullptr), anon_cred(nullptr), + cert_cred(nullptr), anon(_anon), tlsis(nullptr), tlsos(nullptr), + rawis(nullptr), rawos(nullptr) { #if defined (SSECURITYTLS__USE_DEPRECATED_DH) - dh_params = NULL; + dh_params = nullptr; #endif if (gnutls_global_init() != GNUTLS_E_SUCCESS) @@ -99,32 +99,32 @@ void SSecurityTLS::shutdown() if (anon_cred) { gnutls_anon_free_server_credentials(anon_cred); - anon_cred = 0; + anon_cred = nullptr; } if (cert_cred) { gnutls_certificate_free_credentials(cert_cred); - cert_cred = 0; + cert_cred = nullptr; } if (rawis && rawos) { sc->setStreams(rawis, rawos); - rawis = NULL; - rawos = NULL; + rawis = nullptr; + rawos = nullptr; } if (tlsis) { delete tlsis; - tlsis = NULL; + tlsis = nullptr; } if (tlsos) { delete tlsos; - tlsos = NULL; + tlsos = nullptr; } if (session) { gnutls_deinit(session); - session = 0; + session = nullptr; } } @@ -151,7 +151,7 @@ bool SSecurityTLS::processMsg() throw AuthFailureException("gnutls_set_default_priority failed"); try { - setParams(session); + setParams(); } catch(...) { os->writeU8(0); @@ -190,7 +190,7 @@ bool SSecurityTLS::processMsg() return true; } -void SSecurityTLS::setParams(gnutls_session_t session) +void SSecurityTLS::setParams() { static const char kx_anon_priority[] = ":+ANON-ECDH:+ANON-DH"; @@ -203,7 +203,7 @@ void SSecurityTLS::setParams(gnutls_session_t session) prio = (char*)malloc(strlen(Security::GnuTLSPriority) + strlen(kx_anon_priority) + 1); - if (prio == NULL) + if (prio == nullptr) throw AuthFailureException("Not enough memory for GnuTLS priority string"); strcpy(prio, Security::GnuTLSPriority); @@ -239,7 +239,7 @@ void SSecurityTLS::setParams(gnutls_session_t session) prio = (char*)malloc(strlen(gnutls_default_priority) + strlen(kx_anon_priority) + 1); - if (prio == NULL) + if (prio == nullptr) throw AuthFailureException("Not enough memory for GnuTLS priority string"); strcpy(prio, gnutls_default_priority); diff --git a/common/rfb/SSecurityTLS.h b/common/rfb/SSecurityTLS.h index d0f735fe..c29ee474 100644 --- a/common/rfb/SSecurityTLS.h +++ b/common/rfb/SSecurityTLS.h @@ -45,16 +45,16 @@ namespace rfb { public: SSecurityTLS(SConnection* sc, bool _anon); virtual ~SSecurityTLS(); - virtual bool processMsg(); - virtual const char* getUserName() const {return 0;} - virtual int getType() const { return anon ? secTypeTLSNone : secTypeX509None;} + bool processMsg() override; + const char* getUserName() const override {return nullptr;} + int getType() const override { return anon ? secTypeTLSNone : secTypeX509None;} static StringParameter X509_CertFile; static StringParameter X509_KeyFile; protected: void shutdown(); - void setParams(gnutls_session_t session); + void setParams(); private: gnutls_session_t session; diff --git a/common/rfb/SSecurityVeNCrypt.cxx b/common/rfb/SSecurityVeNCrypt.cxx index 2813f299..ce160503 100644 --- a/common/rfb/SSecurityVeNCrypt.cxx +++ b/common/rfb/SSecurityVeNCrypt.cxx @@ -38,10 +38,11 @@ using namespace std; static LogWriter vlog("SVeNCrypt"); -SSecurityVeNCrypt::SSecurityVeNCrypt(SConnection* sc, SecurityServer *sec) - : SSecurity(sc), security(sec) +SSecurityVeNCrypt::SSecurityVeNCrypt(SConnection* sc_, + SecurityServer *sec) + : SSecurity(sc_), security(sec) { - ssecurity = NULL; + ssecurity = nullptr; haveSentVersion = false; haveRecvdMajorVersion = false; haveRecvdMinorVersion = false; @@ -51,7 +52,7 @@ SSecurityVeNCrypt::SSecurityVeNCrypt(SConnection* sc, SecurityServer *sec) haveChosenType = false; chosenType = secTypeVeNCrypt; numTypes = 0; - subTypes = NULL; + subTypes = nullptr; } SSecurityVeNCrypt::~SSecurityVeNCrypt() @@ -175,14 +176,14 @@ bool SSecurityVeNCrypt::processMsg() const char* SSecurityVeNCrypt::getUserName() const { - if (ssecurity == NULL) - return NULL; + if (ssecurity == nullptr) + return nullptr; return ssecurity->getUserName(); } AccessRights SSecurityVeNCrypt::getAccessRights() const { - if (ssecurity == NULL) + if (ssecurity == nullptr) return SSecurity::getAccessRights(); return ssecurity->getAccessRights(); } diff --git a/common/rfb/SSecurityVeNCrypt.h b/common/rfb/SSecurityVeNCrypt.h index 91713f89..ea2bb6fb 100644 --- a/common/rfb/SSecurityVeNCrypt.h +++ b/common/rfb/SSecurityVeNCrypt.h @@ -34,10 +34,10 @@ namespace rfb { public: SSecurityVeNCrypt(SConnection* sc, SecurityServer *sec); ~SSecurityVeNCrypt(); - virtual bool processMsg(); - virtual int getType() const { return chosenType; } - virtual const char* getUserName() const; - virtual AccessRights getAccessRights() const; + bool processMsg() override; + int getType() const override { return chosenType; } + const char* getUserName() const override; + AccessRights getAccessRights() const override; protected: SSecurity *ssecurity; diff --git a/common/rfb/SSecurityVncAuth.cxx b/common/rfb/SSecurityVncAuth.cxx index c1ef1f1c..1276f68a 100644 --- a/common/rfb/SSecurityVncAuth.cxx +++ b/common/rfb/SSecurityVncAuth.cxx @@ -52,8 +52,8 @@ VncAuthPasswdParameter SSecurityVncAuth::vncAuthPasswd ("Password", "Obfuscated binary encoding of the password which clients must supply to " "access the server", &SSecurityVncAuth::vncAuthPasswdFile); -SSecurityVncAuth::SSecurityVncAuth(SConnection* sc) - : SSecurity(sc), sentChallenge(false), +SSecurityVncAuth::SSecurityVncAuth(SConnection* sc_) + : SSecurity(sc_), sentChallenge(false), pg(&vncAuthPasswd), accessRights(AccessNone) { } @@ -116,10 +116,12 @@ bool SSecurityVncAuth::processMsg() throw AuthFailureException(); } -VncAuthPasswdParameter::VncAuthPasswdParameter(const char* name, +VncAuthPasswdParameter::VncAuthPasswdParameter(const char* name_, const char* desc, StringParameter* passwdFile_) -: BinaryParameter(name, desc, 0, 0, ConfServer), passwdFile(passwdFile_) { +: BinaryParameter(name_, desc, nullptr, 0, ConfServer), + passwdFile(passwdFile_) +{ } void VncAuthPasswdParameter::getVncAuthPasswd(std::string *password, std::string *readOnlyPassword) { @@ -151,8 +153,8 @@ void VncAuthPasswdParameter::getVncAuthPasswd(std::string *password, std::string } } - assert(password != NULL); - assert(readOnlyPassword != NULL); + assert(password != nullptr); + assert(readOnlyPassword != nullptr); try { *password = deobfuscate(obfuscated.data(), obfuscated.size()); diff --git a/common/rfb/SSecurityVncAuth.h b/common/rfb/SSecurityVncAuth.h index 7f27b02b..532abe0a 100644 --- a/common/rfb/SSecurityVncAuth.h +++ b/common/rfb/SSecurityVncAuth.h @@ -44,7 +44,7 @@ namespace rfb { class VncAuthPasswdParameter : public VncAuthPasswdGetter, BinaryParameter { public: VncAuthPasswdParameter(const char* name, const char* desc, StringParameter* passwdFile_); - virtual void getVncAuthPasswd(std::string *password, std::string *readOnlyPassword); + void getVncAuthPasswd(std::string *password, std::string *readOnlyPassword) override; protected: StringParameter* passwdFile; }; @@ -52,10 +52,10 @@ namespace rfb { class SSecurityVncAuth : public SSecurity { public: SSecurityVncAuth(SConnection* sc); - virtual bool processMsg(); - virtual int getType() const {return secTypeVncAuth;} - virtual const char* getUserName() const {return 0;} - virtual AccessRights getAccessRights() const { return accessRights; } + bool processMsg() override; + int getType() const override {return secTypeVncAuth;} + const char* getUserName() const override {return nullptr;} + AccessRights getAccessRights() const override { return accessRights; } static StringParameter vncAuthPasswdFile; static VncAuthPasswdParameter vncAuthPasswd; private: diff --git a/common/rfb/Security.cxx b/common/rfb/Security.cxx index caf6420f..01191c65 100644 --- a/common/rfb/Security.cxx +++ b/common/rfb/Security.cxx @@ -21,29 +21,14 @@ #include <config.h> #endif -#include <assert.h> -#include <stdlib.h> #include <string.h> -#include <rfb/CSecurityNone.h> -#include <rfb/CSecurityStack.h> -#include <rfb/CSecurityVeNCrypt.h> -#include <rfb/CSecurityVncAuth.h> -#include <rfb/CSecurityPlain.h> -#include <rdr/Exception.h> + +#include <algorithm> + #include <rfb/LogWriter.h> #include <rfb/Security.h> -#include <rfb/SSecurityNone.h> -#include <rfb/SSecurityStack.h> -#include <rfb/SSecurityPlain.h> -#include <rfb/SSecurityVncAuth.h> -#include <rfb/SSecurityVeNCrypt.h> -#ifdef HAVE_GNUTLS -#include <rfb/CSecurityTLS.h> -#include <rfb/SSecurityTLS.h> -#endif #include <rfb/util.h> -using namespace rdr; using namespace rfb; using namespace std; @@ -67,23 +52,22 @@ Security::Security(StringParameter &secTypes) const std::list<uint8_t> Security::GetEnabledSecTypes(void) { list<uint8_t> result; - list<uint32_t>::iterator i; /* Partial workaround for Vino's stupid behaviour. It doesn't allow * the basic authentication types as part of the VeNCrypt handshake, * making it impossible for a client to do opportunistic encryption. * At least make it possible to connect when encryption is explicitly * disabled. */ - for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++) { - if (*i >= 0x100) { + for (uint32_t type : enabledSecTypes) { + if (type >= 0x100) { result.push_back(secTypeVeNCrypt); break; } } - for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++) - if (*i < 0x100) - result.push_back(*i); + for (uint32_t type : enabledSecTypes) + if (type < 0x100) + result.push_back(type); return result; } @@ -91,33 +75,28 @@ const std::list<uint8_t> Security::GetEnabledSecTypes(void) const std::list<uint32_t> Security::GetEnabledExtSecTypes(void) { list<uint32_t> result; - list<uint32_t>::iterator i; - for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++) - if (*i != secTypeVeNCrypt) /* Do not include VeNCrypt type to avoid loops */ - result.push_back(*i); + for (uint32_t type : enabledSecTypes) + if (type != secTypeVeNCrypt) /* Do not include VeNCrypt type to avoid loops */ + result.push_back(type); return result; } void Security::EnableSecType(uint32_t secType) { - list<uint32_t>::iterator i; - - for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++) - if (*i == secType) - return; + if (std::find(enabledSecTypes.begin(), enabledSecTypes.end(), + secType) != enabledSecTypes.end()) + return; enabledSecTypes.push_back(secType); } bool Security::IsSupported(uint32_t secType) { - list<uint32_t>::iterator i; - - for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++) - if (*i == secType) - return true; + if (std::find(enabledSecTypes.begin(), enabledSecTypes.end(), + secType) != enabledSecTypes.end()) + return true; if (secType == secTypeVeNCrypt) return true; @@ -126,15 +105,14 @@ bool Security::IsSupported(uint32_t secType) char *Security::ToString(void) { - list<uint32_t>::iterator i; static char out[128]; /* Should be enough */ bool firstpass = true; const char *name; memset(out, 0, sizeof(out)); - for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++) { - name = secTypeName(*i); + for (uint32_t type : enabledSecTypes) { + name = secTypeName(type); if (name[0] == '[') /* Unknown security type */ continue; diff --git a/common/rfb/SecurityClient.cxx b/common/rfb/SecurityClient.cxx index 1350640d..12860662 100644 --- a/common/rfb/SecurityClient.cxx +++ b/common/rfb/SecurityClient.cxx @@ -41,9 +41,9 @@ using namespace rdr; using namespace rfb; -UserPasswdGetter *CSecurity::upg = NULL; +UserPasswdGetter *CSecurity::upg = nullptr; #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE) -UserMsgBox *CSecurity::msg = NULL; +UserMsgBox *CSecurity::msg = nullptr; #endif StringParameter SecurityClient::secTypes @@ -67,9 +67,9 @@ ConfViewer); CSecurity* SecurityClient::GetCSecurity(CConnection* cc, uint32_t secType) { - assert (CSecurity::upg != NULL); /* (upg == NULL) means bug in the viewer */ + assert (CSecurity::upg != nullptr); /* (upg == nullptr) means bug in the viewer */ #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE) - assert (CSecurity::msg != NULL); + assert (CSecurity::msg != nullptr); #endif if (!IsSupported(secType)) diff --git a/common/rfb/ServerParams.cxx b/common/rfb/ServerParams.cxx index 6af446c2..9f6f5307 100644 --- a/common/rfb/ServerParams.cxx +++ b/common/rfb/ServerParams.cxx @@ -38,7 +38,7 @@ ServerParams::ServerParams() { setName(""); - cursor_ = new Cursor(0, 0, Point(), NULL); + cursor_ = new Cursor(0, 0, Point(), nullptr); clipFlags = 0; memset(clipSizes, 0, sizeof(clipSizes)); diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx index 54b620ea..807f71a5 100644 --- a/common/rfb/TightDecoder.cxx +++ b/common/rfb/TightDecoder.cxx @@ -345,7 +345,7 @@ void TightDecoder::decodeRect(const Rect& r, const uint8_t* buffer, size_t rowSize, dataSize; uint8_t* netbuf; - netbuf = NULL; + netbuf = nullptr; if (palSize != 0) { if (palSize <= 2) @@ -387,7 +387,7 @@ void TightDecoder::decodeRect(const Rect& r, const uint8_t* buffer, zis[streamId].readBytes(netbuf, dataSize); zis[streamId].flushUnderlying(); - zis[streamId].setUnderlying(NULL, 0); + zis[streamId].setUnderlying(nullptr, 0); delete ms; bufptr = netbuf; diff --git a/common/rfb/TightDecoder.h b/common/rfb/TightDecoder.h index 764f138e..d569a7fd 100644 --- a/common/rfb/TightDecoder.h +++ b/common/rfb/TightDecoder.h @@ -31,18 +31,17 @@ namespace rfb { public: TightDecoder(); virtual ~TightDecoder(); - virtual bool readRect(const Rect& r, rdr::InStream* is, - const ServerParams& server, rdr::OutStream* os); - virtual bool doRectsConflict(const Rect& rectA, - const uint8_t* bufferA, - size_t buflenA, - const Rect& rectB, - const uint8_t* bufferB, - size_t buflenB, - const ServerParams& server); - virtual void decodeRect(const Rect& r, const uint8_t* buffer, - size_t buflen, const ServerParams& server, - ModifiablePixelBuffer* pb); + bool readRect(const Rect& r, rdr::InStream* is, + const ServerParams& server, + rdr::OutStream* os) override; + bool doRectsConflict(const Rect& rectA, + const uint8_t* bufferA, size_t buflenA, + const Rect& rectB, + const uint8_t* bufferB, size_t buflenB, + const ServerParams& server) override; + void decodeRect(const Rect& r, const uint8_t* buffer, + size_t buflen, const ServerParams& server, + ModifiablePixelBuffer* pb) override; private: uint32_t readCompact(rdr::InStream* is); diff --git a/common/rfb/TightEncoder.cxx b/common/rfb/TightEncoder.cxx index 1a169a3d..169b74f7 100644 --- a/common/rfb/TightEncoder.cxx +++ b/common/rfb/TightEncoder.cxx @@ -60,8 +60,8 @@ static const TightConf conf[10] = { { 9, 9, 9 } // 9 }; -TightEncoder::TightEncoder(SConnection* conn) : - Encoder(conn, encodingTight, EncoderPlain, 256) +TightEncoder::TightEncoder(SConnection* conn_) : + Encoder(conn_, encodingTight, EncoderPlain, 256) { setCompressLevel(-1); } @@ -260,12 +260,12 @@ void TightEncoder::flushZlibOutStream(rdr::OutStream* os_) rdr::ZlibOutStream* zos; zos = dynamic_cast<rdr::ZlibOutStream*>(os_); - if (zos == NULL) + if (zos == nullptr) return; zos->cork(false); zos->flush(); - zos->setUnderlying(NULL); + zos->setUnderlying(nullptr); os = conn->getOutStream(); diff --git a/common/rfb/TightEncoder.h b/common/rfb/TightEncoder.h index 0608eb09..3a7210c7 100644 --- a/common/rfb/TightEncoder.h +++ b/common/rfb/TightEncoder.h @@ -31,14 +31,14 @@ namespace rfb { TightEncoder(SConnection* conn); virtual ~TightEncoder(); - virtual bool isSupported(); + bool isSupported() override; - virtual void setCompressLevel(int level); + void setCompressLevel(int level) override; - virtual void writeRect(const PixelBuffer* pb, const Palette& palette); - virtual void writeSolidRect(int width, int height, - const PixelFormat& pf, - const uint8_t* colour); + void writeRect(const PixelBuffer* pb, + const Palette& palette) override; + void writeSolidRect(int width, int height, const PixelFormat& pf, + const uint8_t* colour) override; protected: void writeMonoRect(const PixelBuffer* pb, const Palette& palette); diff --git a/common/rfb/TightJPEGEncoder.cxx b/common/rfb/TightJPEGEncoder.cxx index 5c8706ee..de8fd77f 100644 --- a/common/rfb/TightJPEGEncoder.cxx +++ b/common/rfb/TightJPEGEncoder.cxx @@ -68,8 +68,8 @@ static const struct TightJPEGConfiguration conf[10] = { }; -TightJPEGEncoder::TightJPEGEncoder(SConnection* conn) : - Encoder(conn, encodingTight, +TightJPEGEncoder::TightJPEGEncoder(SConnection* conn_) : + Encoder(conn_, encodingTight, (EncoderFlags)(EncoderUseNativePF | EncoderLossy), -1, 9), qualityLevel(-1), fineQuality(-1), fineSubsampling(subsampleUndefined) { diff --git a/common/rfb/TightJPEGEncoder.h b/common/rfb/TightJPEGEncoder.h index 002deabb..81d9f40d 100644 --- a/common/rfb/TightJPEGEncoder.h +++ b/common/rfb/TightJPEGEncoder.h @@ -30,17 +30,17 @@ namespace rfb { TightJPEGEncoder(SConnection* conn); virtual ~TightJPEGEncoder(); - virtual bool isSupported(); + bool isSupported() override; - virtual void setQualityLevel(int level); - virtual void setFineQualityLevel(int quality, int subsampling); + void setQualityLevel(int level) override; + void setFineQualityLevel(int quality, int subsampling) override; - virtual int getQualityLevel(); + int getQualityLevel() override; - virtual void writeRect(const PixelBuffer* pb, const Palette& palette); - virtual void writeSolidRect(int width, int height, - const PixelFormat& pf, - const uint8_t* colour); + void writeRect(const PixelBuffer* pb, + const Palette& palette) override; + void writeSolidRect(int width, int height, const PixelFormat& pf, + const uint8_t* colour) override; protected: void writeCompact(uint32_t value, rdr::OutStream* os); diff --git a/common/rfb/Timer.cxx b/common/rfb/Timer.cxx index e9ae5227..5216c7e3 100644 --- a/common/rfb/Timer.cxx +++ b/common/rfb/Timer.cxx @@ -26,6 +26,8 @@ #include <stdio.h> #include <sys/time.h> +#include <algorithm> + #include <rfb/Timer.h> #include <rfb/util.h> #include <rfb/LogWriter.h> @@ -63,7 +65,7 @@ int Timer::checkTimeouts() { if (pending.empty()) return -1; - gettimeofday(&start, 0); + gettimeofday(&start, nullptr); while (pending.front()->isBefore(start)) { Timer* timer; @@ -81,7 +83,7 @@ int Timer::checkTimeouts() { int Timer::getNextTimeout() { timeval now; - gettimeofday(&now, 0); + gettimeofday(&now, nullptr); if (pending.empty()) return -1; @@ -115,7 +117,7 @@ void Timer::insertTimer(Timer* t) { void Timer::start(int timeoutMs_) { timeval now; - gettimeofday(&now, 0); + gettimeofday(&now, nullptr); stop(); timeoutMs = timeoutMs_; dueTime = addMillis(now, timeoutMs); @@ -125,7 +127,7 @@ void Timer::start(int timeoutMs_) { void Timer::repeat(int timeoutMs_) { timeval now; - gettimeofday(&now, 0); + gettimeofday(&now, nullptr); if (isStarted()) { vlog.error("Incorrectly repeating already running timer"); @@ -153,12 +155,8 @@ void Timer::stop() { } bool Timer::isStarted() { - std::list<Timer*>::iterator i; - for (i=pending.begin(); i!=pending.end(); i++) { - if (*i == this) - return true; - } - return false; + return std::find(pending.begin(), pending.end(), + this) != pending.end(); } int Timer::getTimeoutMs() { @@ -167,7 +165,7 @@ int Timer::getTimeoutMs() { int Timer::getRemainingMs() { timeval now; - gettimeofday(&now, 0); + gettimeofday(&now, nullptr); return __rfbmax(0, diffTimeMillis(dueTime, now)); } diff --git a/common/rfb/Timer.h b/common/rfb/Timer.h index 36ec46c5..362cb84e 100644 --- a/common/rfb/Timer.h +++ b/common/rfb/Timer.h @@ -124,7 +124,7 @@ namespace rfb { MethodTimer(T* obj_, void (T::*cb_)(Timer*)) : Timer(this), obj(obj_), cb(cb_) {} - virtual void handleTimeout(Timer* t) { (obj->*cb)(t); } + void handleTimeout(Timer* t) override { return (obj->*cb)(t); } private: T* obj; diff --git a/common/rfb/UnixPasswordValidator.h b/common/rfb/UnixPasswordValidator.h index 28d083a1..4d623d6c 100644 --- a/common/rfb/UnixPasswordValidator.h +++ b/common/rfb/UnixPasswordValidator.h @@ -28,7 +28,7 @@ namespace rfb class UnixPasswordValidator: public PasswordValidator { protected: bool validateInternal(SConnection * sc, const char *username, - const char *password); + const char *password) override; }; } diff --git a/common/rfb/UpdateTracker.h b/common/rfb/UpdateTracker.h index 8983b378..e91b9621 100644 --- a/common/rfb/UpdateTracker.h +++ b/common/rfb/UpdateTracker.h @@ -53,14 +53,14 @@ namespace rfb { class ClippingUpdateTracker : public UpdateTracker { public: - ClippingUpdateTracker() : ut(0) {} + ClippingUpdateTracker() : ut(nullptr) {} ClippingUpdateTracker(UpdateTracker* ut_, const Rect& r=Rect()) : ut(ut_), clipRect(r) {} void setUpdateTracker(UpdateTracker* ut_) {ut = ut_;} void setClipRect(const Rect& cr) {clipRect = cr;} - virtual void add_changed(const Region ®ion); - virtual void add_copied(const Region &dest, const Point &delta); + void add_changed(const Region ®ion) override; + void add_copied(const Region &dest, const Point &delta) override; protected: UpdateTracker* ut; Rect clipRect; @@ -71,8 +71,8 @@ namespace rfb { SimpleUpdateTracker(); virtual ~SimpleUpdateTracker(); - virtual void add_changed(const Region ®ion); - virtual void add_copied(const Region &dest, const Point &delta); + void add_changed(const Region ®ion) override; + void add_copied(const Region &dest, const Point &delta) override; virtual void subtract(const Region& region); // Fill the supplied UpdateInfo structure with update information diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 306bba1d..a40a1a30 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -48,7 +48,7 @@ using namespace rfb; static LogWriter vlog("VNCSConnST"); -static Cursor emptyCursor(0, 0, Point(0, 0), NULL); +static Cursor emptyCursor(0, 0, Point(0, 0), nullptr); VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s, bool reverse, AccessRights ar) @@ -56,7 +56,7 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s, sock(s), reverseConnection(reverse), inProcessMessages(false), pendingSyncFence(false), syncFence(false), fenceFlags(0), - fenceDataLen(0), fenceData(NULL), congestionTimer(this), + fenceDataLen(0), fenceData(nullptr), congestionTimer(this), losslessTimer(this), server(server_), updateRenderedCursor(false), removeRenderedCursor(false), continuousUpdates(false), encodeManager(this), idleTimer(this), @@ -409,7 +409,7 @@ bool VNCSConnectionST::needRenderedCursor() if (!client.supportsLocalCursor()) return true; if ((server->getCursorPos() != pointerEventPos) && - (time(0) - pointerEventTime) > 0) + (time(nullptr) - pointerEventTime) > 0) return true; return false; @@ -481,7 +481,7 @@ void VNCSConnectionST::pointerEvent(const Point& pos, int buttonMask) { if (rfb::Server::idleTimeout) idleTimer.start(secsToMillis(rfb::Server::idleTimeout)); - pointerEventTime = time(0); + pointerEventTime = time(nullptr); if (!accessCheck(AccessPtrEvents)) return; if (!rfb::Server::acceptPointerEvents) return; pointerEventPos = pos; @@ -690,7 +690,7 @@ void VNCSConnectionST::fence(uint32_t flags, unsigned len, const uint8_t data[]) fenceFlags = flags & (fenceFlagBlockBefore | fenceFlagBlockAfter | fenceFlagSyncNext); fenceDataLen = len; delete [] fenceData; - fenceData = NULL; + fenceData = nullptr; if (len > 0) { fenceData = new uint8_t[len]; memcpy(fenceData, data, len); @@ -1001,7 +1001,7 @@ void VNCSConnectionST::writeDataUpdate() // Does the client need a server-side rendered cursor? - cursor = NULL; + cursor = nullptr; if (needRenderedCursor()) { Rect renderedCursorRect; @@ -1083,7 +1083,7 @@ void VNCSConnectionST::writeLosslessRefresh() // Prepare the cursor in case it overlaps with a region getting // refreshed - cursor = NULL; + cursor = nullptr; if (needRenderedCursor()) cursor = server->getRenderedCursor(); diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h index 3a9ec242..e9badd72 100644 --- a/common/rfb/VNCSConnectionST.h +++ b/common/rfb/VNCSConnectionST.h @@ -46,8 +46,8 @@ namespace rfb { // SConnection methods - virtual bool accessCheck(AccessRights ar) const; - virtual void close(const char* reason); + bool accessCheck(AccessRights ar) const override; + void close(const char* reason) override; using SConnection::authenticated; @@ -118,30 +118,32 @@ namespace rfb { private: // SConnection callbacks - // These methods are invoked as callbacks from processMsg() - - virtual void authSuccess(); - virtual void queryConnection(const char* userName); - virtual void clientInit(bool shared); - virtual void setPixelFormat(const PixelFormat& pf); - virtual void pointerEvent(const Point& pos, int buttonMask); - virtual void keyEvent(uint32_t keysym, uint32_t keycode, bool down); - virtual void framebufferUpdateRequest(const Rect& r, bool incremental); - virtual void setDesktopSize(int fb_width, int fb_height, - const ScreenSet& layout); - virtual void fence(uint32_t flags, unsigned len, const uint8_t data[]); - virtual void enableContinuousUpdates(bool enable, - int x, int y, int w, int h); - virtual void handleClipboardRequest(); - virtual void handleClipboardAnnounce(bool available); - virtual void handleClipboardData(const char* data); - virtual void supportsLocalCursor(); - virtual void supportsFence(); - virtual void supportsContinuousUpdates(); - virtual void supportsLEDState(); + // These methods are invoked as callbacks from processMsg( + void authSuccess() override; + void queryConnection(const char* userName) override; + void clientInit(bool shared) override; + void setPixelFormat(const PixelFormat& pf) override; + void pointerEvent(const Point& pos, int buttonMask) override; + void keyEvent(uint32_t keysym, uint32_t keycode, + bool down) override; + void framebufferUpdateRequest(const Rect& r, + bool incremental) override; + void setDesktopSize(int fb_width, int fb_height, + const ScreenSet& layout) override; + void fence(uint32_t flags, unsigned len, + const uint8_t data[]) override; + void enableContinuousUpdates(bool enable, + int x, int y, int w, int h) override; + void handleClipboardRequest() override; + void handleClipboardAnnounce(bool available) override; + void handleClipboardData(const char* data) override; + void supportsLocalCursor() override; + void supportsFence() override; + void supportsContinuousUpdates() override; + void supportsLEDState() override; // Timer callbacks - virtual void handleTimeout(Timer* t); + void handleTimeout(Timer* t) override; // Internal methods diff --git a/common/rfb/VNCServer.h b/common/rfb/VNCServer.h index 3ac9fb94..4e3a5b23 100644 --- a/common/rfb/VNCServer.h +++ b/common/rfb/VNCServer.h @@ -115,7 +115,7 @@ namespace rfb { // acceptance, or false for rejection, in which case a string // reason may also be given. virtual void approveConnection(network::Socket* sock, bool accept, - const char* reason = NULL) = 0; + const char* reason = nullptr) = 0; // - Close all currently-connected clients, by calling // their close() method with the supplied reason. diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index b9579f12..a8fa1739 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -83,10 +83,10 @@ static LogWriter connectionsLog("Connections"); VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) : blHosts(&blacklist), desktop(desktop_), desktopStarted(false), - blockCounter(0), pb(0), ledState(ledUnknown), - name(name_), pointerClient(0), clipboardClient(0), + blockCounter(0), pb(nullptr), ledState(ledUnknown), + name(name_), pointerClient(nullptr), clipboardClient(nullptr), pointerClientTime(0), - comparer(0), cursor(new Cursor(0, 0, Point(), NULL)), + comparer(nullptr), cursor(new Cursor(0, 0, Point(), nullptr)), renderedCursorInvalid(false), keyRemapper(&KeyRemapper::defInstance), idleTimer(this), disconnectTimer(this), connectTimer(this), @@ -177,19 +177,19 @@ void VNCServerST::removeSocket(network::Socket* sock) { if ((*ci)->getSock() == sock) { // - Remove any references to it if (pointerClient == *ci) - pointerClient = NULL; + pointerClient = nullptr; if (clipboardClient == *ci) handleClipboardAnnounce(*ci, false); clipboardRequestors.remove(*ci); - std::string name((*ci)->getPeerEndpoint()); + std::string peer((*ci)->getPeerEndpoint()); // - Delete the per-Socket resources delete *ci; clients.remove(*ci); - connectionsLog.status("closed: %s", name.c_str()); + connectionsLog.status("closed: %s", peer.c_str()); // - Check that the desktop object is still required if (authClientCount() == 0) @@ -275,7 +275,7 @@ void VNCServerST::setPixelBuffer(PixelBuffer* pb_, const ScreenSet& layout) pb = pb_; delete comparer; - comparer = 0; + comparer = nullptr; if (!pb) { screenLayout = ScreenSet(); @@ -297,9 +297,8 @@ void VNCServerST::setPixelBuffer(PixelBuffer* pb_, const ScreenSet& layout) renderedCursorInvalid = true; add_changed(pb->getRect()); - std::list<VNCSConnectionST*>::iterator ci, ci_next; - for (ci=clients.begin();ci!=clients.end();ci=ci_next) { - ci_next = ci; ci_next++; + std::list<VNCSConnectionST*>::iterator ci; + for (ci = clients.begin(); ci != clients.end(); ++ci) { (*ci)->pixelBufferChange(); // Since the new pixel buffer means an ExtendedDesktopSize needs to // be sent anyway, we don't need to call screenLayoutChange. @@ -346,16 +345,14 @@ void VNCServerST::setScreenLayout(const ScreenSet& layout) screenLayout = layout; - std::list<VNCSConnectionST*>::iterator ci, ci_next; - for (ci=clients.begin();ci!=clients.end();ci=ci_next) { - ci_next = ci; ci_next++; + std::list<VNCSConnectionST*>::iterator ci; + for (ci = clients.begin(); ci != clients.end(); ++ci) (*ci)->screenLayoutChangeOrClose(reasonServer); - } } void VNCServerST::requestClipboard() { - if (clipboardClient == NULL) { + if (clipboardClient == nullptr) { slog.debug("Got request for client clipboard but no client currently owns the clipboard"); return; } @@ -365,54 +362,46 @@ void VNCServerST::requestClipboard() void VNCServerST::announceClipboard(bool available) { - std::list<VNCSConnectionST*>::iterator ci, ci_next; + std::list<VNCSConnectionST*>::iterator ci; clipboardRequestors.clear(); - for (ci = clients.begin(); ci != clients.end(); ci = ci_next) { - ci_next = ci; ci_next++; + for (ci = clients.begin(); ci != clients.end(); ++ci) (*ci)->announceClipboardOrClose(available); - } } void VNCServerST::sendClipboardData(const char* data) { - std::list<VNCSConnectionST*>::iterator ci, ci_next; + std::list<VNCSConnectionST*>::iterator ci; - if (strchr(data, '\r') != NULL) + if (strchr(data, '\r') != nullptr) throw Exception("Invalid carriage return in clipboard data"); for (ci = clipboardRequestors.begin(); - ci != clipboardRequestors.end(); ci = ci_next) { - ci_next = ci; ci_next++; + ci != clipboardRequestors.end(); ++ci) (*ci)->sendClipboardDataOrClose(data); - } clipboardRequestors.clear(); } void VNCServerST::bell() { - std::list<VNCSConnectionST*>::iterator ci, ci_next; - for (ci = clients.begin(); ci != clients.end(); ci = ci_next) { - ci_next = ci; ci_next++; + std::list<VNCSConnectionST*>::iterator ci; + for (ci = clients.begin(); ci != clients.end(); ++ci) (*ci)->bellOrClose(); - } } void VNCServerST::setName(const char* name_) { name = name_; - std::list<VNCSConnectionST*>::iterator ci, ci_next; - for (ci = clients.begin(); ci != clients.end(); ci = ci_next) { - ci_next = ci; ci_next++; + std::list<VNCSConnectionST*>::iterator ci; + for (ci = clients.begin(); ci != clients.end(); ++ci) (*ci)->setDesktopNameOrClose(name_); - } } void VNCServerST::add_changed(const Region& region) { - if (comparer == NULL) + if (comparer == nullptr) return; comparer->add_changed(region); @@ -421,7 +410,7 @@ void VNCServerST::add_changed(const Region& region) void VNCServerST::add_copied(const Region& dest, const Point& delta) { - if (comparer == NULL) + if (comparer == nullptr) return; comparer->add_copied(dest, delta); @@ -437,9 +426,8 @@ void VNCServerST::setCursor(int width, int height, const Point& newHotspot, renderedCursorInvalid = true; - std::list<VNCSConnectionST*>::iterator ci, ci_next; - for (ci = clients.begin(); ci != clients.end(); ci = ci_next) { - ci_next = ci; ci_next++; + std::list<VNCSConnectionST*>::iterator ci; + for (ci = clients.begin(); ci != clients.end(); ++ci) { (*ci)->renderedCursorChange(); (*ci)->setCursorOrClose(); } @@ -461,17 +449,15 @@ void VNCServerST::setCursorPos(const Point& pos, bool warped) void VNCServerST::setLEDState(unsigned int state) { - std::list<VNCSConnectionST*>::iterator ci, ci_next; + std::list<VNCSConnectionST*>::iterator ci; if (state == ledState) return; ledState = state; - for (ci = clients.begin(); ci != clients.end(); ci = ci_next) { - ci_next = ci; ci_next++; + for (ci = clients.begin(); ci != clients.end(); ++ci) (*ci)->setLEDStateOrClose(state); - } } // Event handlers @@ -498,14 +484,14 @@ void VNCServerST::keyEvent(uint32_t keysym, uint32_t keycode, bool down) void VNCServerST::pointerEvent(VNCSConnectionST* client, const Point& pos, int buttonMask) { - time_t now = time(0); + time_t now = time(nullptr); if (rfb::Server::maxIdleTime) idleTimer.start(secsToMillis(rfb::Server::maxIdleTime)); // Let one client own the cursor whilst buttons are pressed in order // to provide a bit more sane user experience. But limit the time to // prevent locking out all others when e.g. the network is down. - if ((pointerClient != NULL) && (pointerClient != client) && + if ((pointerClient != nullptr) && (pointerClient != client) && ((now - pointerClientTime) < 10)) return; @@ -513,7 +499,7 @@ void VNCServerST::pointerEvent(VNCSConnectionST* client, if (buttonMask) pointerClient = client; else - pointerClient = NULL; + pointerClient = nullptr; desktop->pointerEvent(pos, buttonMask); } @@ -533,7 +519,7 @@ void VNCServerST::handleClipboardAnnounce(VNCSConnectionST* client, else { if (client != clipboardClient) return; - clipboardClient = NULL; + clipboardClient = nullptr; } desktop->handleClipboardAnnounce(available); } @@ -553,7 +539,7 @@ unsigned int VNCServerST::setDesktopSize(VNCSConnectionST* requester, const ScreenSet& layout) { unsigned int result; - std::list<VNCSConnectionST*>::iterator ci, ci_next; + std::list<VNCSConnectionST*>::iterator ci; // We can't handle a framebuffer larger than this, so don't let a // client set one (see PixelBuffer.cxx) @@ -580,8 +566,7 @@ unsigned int VNCServerST::setDesktopSize(VNCSConnectionST* requester, throw Exception("Desktop configured a different screen layout than requested"); // Notify other clients - for (ci=clients.begin();ci!=clients.end();ci=ci_next) { - ci_next = ci; ci_next++; + for (ci = clients.begin(); ci != clients.end(); ++ci) { if ((*ci) == requester) continue; (*ci)->screenLayoutChangeOrClose(reasonOtherClient); @@ -606,9 +591,8 @@ void VNCServerST::approveConnection(network::Socket* sock, bool accept, void VNCServerST::closeClients(const char* reason, network::Socket* except) { - std::list<VNCSConnectionST*>::iterator i, next_i; - for (i=clients.begin(); i!=clients.end(); i=next_i) { - next_i = i; next_i++; + std::list<VNCSConnectionST*>::iterator i; + for (i = clients.begin(); i != clients.end(); ++i) { if ((*i)->getSock() != except) (*i)->close(reason); } @@ -633,7 +617,7 @@ SConnection* VNCServerST::getConnection(network::Socket* sock) { if ((*ci)->getSock() == sock) return (SConnection*)*ci; } - return 0; + return nullptr; } void VNCServerST::handleTimeout(Timer* t) @@ -697,14 +681,14 @@ void VNCServerST::queryConnection(VNCSConnectionST* client, // - Are we configured to do queries? if (!rfb::Server::queryConnect && !client->getSock()->requiresQuery()) { - approveConnection(client->getSock(), true, NULL); + approveConnection(client->getSock(), true, nullptr); return; } // - Does the client have the right to bypass the query? if (client->accessCheck(AccessNoQuery)) { - approveConnection(client->getSock(), true, NULL); + approveConnection(client->getSock(), true, nullptr); return; } @@ -832,7 +816,7 @@ void VNCServerST::writeUpdate() UpdateInfo ui; Region toCheck; - std::list<VNCSConnectionST*>::iterator ci, ci_next; + std::list<VNCSConnectionST*>::iterator ci; assert(blockCounter == 0); assert(desktopStarted); @@ -861,8 +845,7 @@ void VNCServerST::writeUpdate() comparer->clear(); - for (ci = clients.begin(); ci != clients.end(); ci = ci_next) { - ci_next = ci; ci_next++; + for (ci = clients.begin(); ci != clients.end(); ++ci) { (*ci)->add_copied(ui.copied, ui.copy_delta); (*ci)->add_changed(ui.changed); (*ci)->writeFramebufferUpdateOrClose(); @@ -906,9 +889,8 @@ bool VNCServerST::getComparerState() if (rfb::Server::compareFB != 2) return true; - std::list<VNCSConnectionST*>::iterator ci, ci_next; - for (ci=clients.begin();ci!=clients.end();ci=ci_next) { - ci_next = ci; ci_next++; + std::list<VNCSConnectionST*>::iterator ci; + for (ci = clients.begin(); ci != clients.end(); ++ci) { if ((*ci)->getComparerState()) return true; } diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index 90c8d753..501882aa 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -56,54 +56,54 @@ namespace rfb { // addSocket // Causes the server to allocate an RFB-protocol management // structure for the socket & initialise it. - virtual void addSocket(network::Socket* sock, bool outgoing=false, - AccessRights ar=AccessDefault); + void addSocket(network::Socket* sock, bool outgoing=false, + AccessRights ar=AccessDefault) override; // removeSocket // Clean up any resources associated with the Socket - virtual void removeSocket(network::Socket* sock); + void removeSocket(network::Socket* sock) override; // getSockets() gets a list of sockets. This can be used to generate an // fd_set for calling select(). - virtual void getSockets(std::list<network::Socket*>* sockets); + void getSockets(std::list<network::Socket*>* sockets) override; // processSocketReadEvent // Read more RFB data from the Socket. If an error occurs during // processing then shutdown() is called on the Socket, causing // removeSocket() to be called by the caller at a later time. - virtual void processSocketReadEvent(network::Socket* sock); + void processSocketReadEvent(network::Socket* sock) override; // processSocketWriteEvent // Flush pending data from the Socket on to the network. - virtual void processSocketWriteEvent(network::Socket* sock); - - virtual void blockUpdates(); - virtual void unblockUpdates(); - virtual uint64_t getMsc(); - virtual void queueMsc(uint64_t target); - virtual void setPixelBuffer(PixelBuffer* pb, const ScreenSet& layout); - virtual void setPixelBuffer(PixelBuffer* pb); - virtual void setScreenLayout(const ScreenSet& layout); - virtual const PixelBuffer* getPixelBuffer() const { return pb; } - - virtual void requestClipboard(); - virtual void announceClipboard(bool available); - virtual void sendClipboardData(const char* data); - - virtual void approveConnection(network::Socket* sock, bool accept, - const char* reason); - virtual void closeClients(const char* reason) {closeClients(reason, 0);} - virtual SConnection* getConnection(network::Socket* sock); - - virtual void add_changed(const Region ®ion); - virtual void add_copied(const Region &dest, const Point &delta); - virtual void setCursor(int width, int height, const Point& hotspot, - const uint8_t* data); - virtual void setCursorPos(const Point& p, bool warped); - virtual void setName(const char* name_); - virtual void setLEDState(unsigned state); - - virtual void bell(); + void processSocketWriteEvent(network::Socket* sock) override; + + void blockUpdates() override; + void unblockUpdates() override; + uint64_t getMsc() override; + void queueMsc(uint64_t target) override; + void setPixelBuffer(PixelBuffer* pb, const ScreenSet& layout) override; + void setPixelBuffer(PixelBuffer* pb) override; + void setScreenLayout(const ScreenSet& layout) override; + const PixelBuffer* getPixelBuffer() const override { return pb; } + + void requestClipboard() override; + void announceClipboard(bool available) override; + void sendClipboardData(const char* data) override; + + void approveConnection(network::Socket* sock, bool accept, + const char* reason) override; + void closeClients(const char* reason) override {closeClients(reason, nullptr);} + SConnection* getConnection(network::Socket* sock) override; + + void add_changed(const Region ®ion) override; + void add_copied(const Region &dest, const Point &delta) override; + void setCursor(int width, int height, const Point& hotspot, + const uint8_t* data) override; + void setCursorPos(const Point& p, bool warped) override; + void setName(const char* name_) override; + void setLEDState(unsigned state) override; + + void bell() override; // VNCServerST-only methods @@ -155,7 +155,7 @@ namespace rfb { protected: // Timer callbacks - virtual void handleTimeout(Timer* t); + void handleTimeout(Timer* t) override; // - Internal methods diff --git a/common/rfb/WinPasswdValidator.h b/common/rfb/WinPasswdValidator.h index ef2310a9..340a6234 100644 --- a/common/rfb/WinPasswdValidator.h +++ b/common/rfb/WinPasswdValidator.h @@ -30,7 +30,7 @@ namespace rfb WinPasswdValidator() {}; virtual ~WinPasswdValidator() {}; protected: - bool validateInternal(SConnection *sc, const char* username, const char* password); + bool validateInternal(SConnection *sc, const char* username, const char* password) override; }; } diff --git a/common/rfb/ZRLEDecoder.cxx b/common/rfb/ZRLEDecoder.cxx index 4b768afc..474fd6ca 100644 --- a/common/rfb/ZRLEDecoder.cxx +++ b/common/rfb/ZRLEDecoder.cxx @@ -106,20 +106,19 @@ void ZRLEDecoder::decodeRect(const Rect& r, const uint8_t* buffer, rdr::MemInStream is(buffer, buflen); const rfb::PixelFormat& pf = server.pf(); switch (pf.bpp) { - case 8: zrleDecode<uint8_t>(r, &is, &zis, pf, pb); break; - case 16: zrleDecode<uint16_t>(r, &is, &zis, pf, pb); break; - case 32: zrleDecode<uint32_t>(r, &is, &zis, pf, pb); break; + case 8: zrleDecode<uint8_t>(r, &is, pf, pb); break; + case 16: zrleDecode<uint16_t>(r, &is, pf, pb); break; + case 32: zrleDecode<uint32_t>(r, &is, pf, pb); break; } } template<class T> void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, - rdr::ZlibInStream* zis, const PixelFormat& pf, ModifiablePixelBuffer* pb) { int length = is->readU32(); - zis->setUnderlying(is, length); + zis.setUnderlying(is, length); Rect t; T buf[64 * 64]; @@ -141,24 +140,24 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, t.br.x = __rfbmin(r.br.x, t.tl.x + 64); - zlibHasData(zis, 1); - int mode = zis->readU8(); + zlibHasData(&zis, 1); + int mode = zis.readU8(); bool rle = mode & 128; int palSize = mode & 127; T palette[128]; if (isLowCPixel || isHighCPixel) - zlibHasData(zis, 3 * palSize); + zlibHasData(&zis, 3 * palSize); else - zlibHasData(zis, sizeof(T) * palSize); + zlibHasData(&zis, sizeof(T) * palSize); for (int i = 0; i < palSize; i++) { if (isLowCPixel) - palette[i] = readOpaque24A(zis); + palette[i] = readOpaque24A(&zis); else if (isHighCPixel) - palette[i] = readOpaque24B(zis); + palette[i] = readOpaque24B(&zis); else - palette[i] = readPixel<T>(zis); + palette[i] = readPixel<T>(&zis); } if (palSize == 1) { @@ -173,19 +172,19 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, // raw if (isLowCPixel || isHighCPixel) - zlibHasData(zis, 3 * t.area()); + zlibHasData(&zis, 3 * t.area()); else - zlibHasData(zis, sizeof(T) * t.area()); + zlibHasData(&zis, sizeof(T) * t.area()); if (isLowCPixel || isHighCPixel) { for (T* ptr = buf; ptr < buf+t.area(); ptr++) { if (isLowCPixel) - *ptr = readOpaque24A(zis); + *ptr = readOpaque24A(&zis); else - *ptr = readOpaque24B(zis); + *ptr = readOpaque24B(&zis); } } else { - zis->readBytes((uint8_t*)buf, t.area() * sizeof(T)); + zis.readBytes((uint8_t*)buf, t.area() * sizeof(T)); } } else { @@ -203,8 +202,8 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, while (ptr < eol) { if (nbits == 0) { - zlibHasData(zis, 1); - byte = zis->readU8(); + zlibHasData(&zis, 1); + byte = zis.readU8(); nbits = 8; } nbits -= bppp; @@ -225,20 +224,20 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, while (ptr < end) { T pix; if (isLowCPixel || isHighCPixel) - zlibHasData(zis, 3); + zlibHasData(&zis, 3); else - zlibHasData(zis, sizeof(T)); + zlibHasData(&zis, sizeof(T)); if (isLowCPixel) - pix = readOpaque24A(zis); + pix = readOpaque24A(&zis); else if (isHighCPixel) - pix = readOpaque24B(zis); + pix = readOpaque24B(&zis); else - pix = readPixel<T>(zis); + pix = readPixel<T>(&zis); int len = 1; int b; do { - zlibHasData(zis, 1); - b = zis->readU8(); + zlibHasData(&zis, 1); + b = zis.readU8(); len += b; } while (b == 255); @@ -256,14 +255,14 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, T* ptr = buf; T* end = ptr + t.area(); while (ptr < end) { - zlibHasData(zis, 1); - int index = zis->readU8(); + zlibHasData(&zis, 1); + int index = zis.readU8(); int len = 1; if (index & 128) { int b; do { - zlibHasData(zis, 1); - b = zis->readU8(); + zlibHasData(&zis, 1); + b = zis.readU8(); len += b; } while (b == 255); @@ -285,6 +284,6 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, } } - zis->flushUnderlying(); - zis->setUnderlying(NULL, 0); + zis.flushUnderlying(); + zis.setUnderlying(nullptr, 0); } diff --git a/common/rfb/ZRLEDecoder.h b/common/rfb/ZRLEDecoder.h index e72bf1b6..facf0adc 100644 --- a/common/rfb/ZRLEDecoder.h +++ b/common/rfb/ZRLEDecoder.h @@ -30,16 +30,16 @@ namespace rfb { public: ZRLEDecoder(); virtual ~ZRLEDecoder(); - virtual bool readRect(const Rect& r, rdr::InStream* is, - const ServerParams& server, rdr::OutStream* os); - virtual void decodeRect(const Rect& r, const uint8_t* buffer, - size_t buflen, const ServerParams& server, - ModifiablePixelBuffer* pb); + bool readRect(const Rect& r, rdr::InStream* is, + const ServerParams& server, + rdr::OutStream* os) override; + void decodeRect(const Rect& r, const uint8_t* buffer, + size_t buflen, const ServerParams& server, + ModifiablePixelBuffer* pb) override; private: template<class T> void zrleDecode(const Rect& r, rdr::InStream* is, - rdr::ZlibInStream* zis, const PixelFormat& pf, ModifiablePixelBuffer* pb); private: diff --git a/common/rfb/ZRLEEncoder.cxx b/common/rfb/ZRLEEncoder.cxx index ad3aec1a..1e2c6ef4 100644 --- a/common/rfb/ZRLEEncoder.cxx +++ b/common/rfb/ZRLEEncoder.cxx @@ -36,9 +36,9 @@ static LogWriter vlog("ZRLEEncoder"); IntParameter zlibLevel("ZlibLevel","[DEPRECATED] Zlib compression level",-1); -ZRLEEncoder::ZRLEEncoder(SConnection* conn) - : Encoder(conn, encodingZRLE, EncoderPlain, 127), - zos(0, 2), mos(129*1024) +ZRLEEncoder::ZRLEEncoder(SConnection* conn_) + : Encoder(conn_, encodingZRLE, EncoderPlain, 127), + zos(nullptr, 2), mos(129*1024) { if (zlibLevel != -1) { vlog.info("Warning: The ZlibLevel option is deprecated and is " @@ -50,7 +50,7 @@ ZRLEEncoder::ZRLEEncoder(SConnection* conn) ZRLEEncoder::~ZRLEEncoder() { - zos.setUnderlying(NULL); + zos.setUnderlying(nullptr); } bool ZRLEEncoder::isSupported() diff --git a/common/rfb/ZRLEEncoder.h b/common/rfb/ZRLEEncoder.h index fa89f10f..87d87e94 100644 --- a/common/rfb/ZRLEEncoder.h +++ b/common/rfb/ZRLEEncoder.h @@ -30,14 +30,14 @@ namespace rfb { ZRLEEncoder(SConnection* conn); virtual ~ZRLEEncoder(); - virtual bool isSupported(); + bool isSupported() override; - virtual void setCompressLevel(int level); + void setCompressLevel(int level) override; - virtual void writeRect(const PixelBuffer* pb, const Palette& palette); - virtual void writeSolidRect(int width, int height, - const PixelFormat& pf, - const uint8_t* colour); + void writeRect(const PixelBuffer* pb, + const Palette& palette) override; + void writeSolidRect(int width, int height, const PixelFormat& pf, + const uint8_t* colour) override; protected: void writePaletteTile(const Rect& tile, const PixelBuffer* pb, diff --git a/common/rfb/obfuscate.cxx b/common/rfb/obfuscate.cxx index d40e25c3..2afc1512 100644 --- a/common/rfb/obfuscate.cxx +++ b/common/rfb/obfuscate.cxx @@ -41,7 +41,7 @@ std::vector<uint8_t> rfb::obfuscate(const char *str) { std::vector<uint8_t> buf(8); - assert(str != NULL); + assert(str != nullptr); size_t l = strlen(str), i; for (i=0; i<8; i++) @@ -59,7 +59,7 @@ std::string rfb::deobfuscate(const uint8_t *data, size_t len) if (len != 8) throw rdr::Exception("bad obfuscated password length"); - assert(data != NULL); + assert(data != nullptr); deskey(d3desObfuscationKey, DE1); des((uint8_t*)data, (uint8_t*)buf); diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx index 48f59846..3c62b1df 100644 --- a/common/rfb/util.cxx +++ b/common/rfb/util.cxx @@ -40,7 +40,7 @@ namespace rfb { std::string out; va_start(ap, fmt); - len = vsnprintf(NULL, 0, fmt, ap); + len = vsnprintf(nullptr, 0, fmt, ap); va_end(ap); if (len < 0) @@ -68,13 +68,13 @@ namespace rfb { start = src; do { stop = strchr(start, delimiter); - if (stop == NULL) { + if (stop == nullptr) { out.push_back(start); } else { out.push_back(std::string(start, stop-start)); start = stop + 1; } - } while (stop != NULL); + } while (stop != nullptr); return out; } @@ -621,7 +621,7 @@ namespace rfb { { struct timeval now; - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); return msBetween(then, &now); } |