diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-15 14:01:28 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2023-02-04 14:03:13 +0100 |
commit | e6c5b29f12780303299506fe04f089bc98b80c91 (patch) | |
tree | 90c0ca35d030065f6f8d169a213dc3c4d923f3b6 /common | |
parent | 15a393912673e2ae65b9b3a28f9b82f967c49f98 (diff) | |
download | tigervnc-e6c5b29f12780303299506fe04f089bc98b80c91.tar.gz tigervnc-e6c5b29f12780303299506fe04f089bc98b80c91.zip |
Use std::vector for temporary char arrays
It's more standard and familiar than our custom CharArray type, and it
still gives us automatic freeing of the buffer.
We could probably have used std::unique_ptr instead, but we are
currently targeting older compilers where C++11 isn't standard yet.
Diffstat (limited to 'common')
-rw-r--r-- | common/rfb/CConnection.cxx | 8 | ||||
-rw-r--r-- | common/rfb/CMsgReader.cxx | 23 | ||||
-rw-r--r-- | common/rfb/SMsgReader.cxx | 7 |
3 files changed, 18 insertions, 20 deletions
diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index da036821..8e545b2f 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -360,12 +360,12 @@ bool CConnection::processSecurityReasonMsg() return false; is->clearRestorePoint(); - CharArray reason(len + 1); - is->readBytes(reason.buf, len); - reason.buf[len] = '\0'; + std::vector<char> reason(len + 1); + is->readBytes(reason.data(), len); + reason[len] = '\0'; state_ = RFBSTATE_INVALID; - throw AuthFailureException(reason.buf); + throw AuthFailureException(reason.data()); } bool CConnection::processInitMsg() diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index 42647119..0052d35e 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -33,7 +33,6 @@ #include <rfb/clipboardTypes.h> #include <rfb/Exception.h> #include <rfb/LogWriter.h> -#include <rfb/util.h> #include <rfb/CMsgHandler.h> #include <rfb/CMsgReader.h> @@ -73,10 +72,10 @@ bool CMsgReader::readServerInit() if (!is->hasDataOrRestore(len)) return false; is->clearRestorePoint(); - CharArray name(len + 1); - is->readBytes(name.buf, len); - name.buf[len] = '\0'; - handler->serverInit(width, height, pf, name.buf); + std::vector<char> name(len + 1); + is->readBytes(name.data(), len); + name[len] = '\0'; + handler->serverInit(width, height, pf, name.data()); return true; } @@ -275,9 +274,9 @@ bool CMsgReader::readServerCutText() vlog.error("cut text too long (%d bytes) - ignoring",len); return true; } - CharArray ca(len); - is->readBytes(ca.buf, len); - std::string filtered(convertLF(ca.buf, len)); + std::vector<char> ca(len); + is->readBytes(ca.data(), len); + std::string filtered(convertLF(ca.data(), len)); handler->serverCutText(filtered.c_str()); return true; @@ -762,14 +761,14 @@ bool CMsgReader::readSetDesktopName(int x, int y, int w, int h) return false; is->clearRestorePoint(); - CharArray name(len + 1); - is->readBytes(name.buf, len); - name.buf[len] = '\0'; + std::vector<char> name(len + 1); + is->readBytes(name.data(), len); + name[len] = '\0'; if (x || y || w || h) { vlog.error("Ignoring DesktopName rect with non-zero position/size"); } else { - handler->setName(name.buf); + handler->setName(name.data()); } return true; diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index 3fddf302..28841704 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -32,7 +32,6 @@ #include <rfb/qemuTypes.h> #include <rfb/clipboardTypes.h> #include <rfb/Exception.h> -#include <rfb/util.h> #include <rfb/SMsgHandler.h> #include <rfb/SMsgReader.h> #include <rfb/Configuration.h> @@ -314,9 +313,9 @@ bool SMsgReader::readClientCutText() return true; } - CharArray ca(len); - is->readBytes(ca.buf, len); - std::string filtered(convertLF(ca.buf, len)); + std::vector<char> ca(len); + is->readBytes(ca.data(), len); + std::string filtered(convertLF(ca.data(), len)); handler->clientCutText(filtered.c_str()); return true; |