From 1143ee66e4068f64e8e246bbbf3c38c4861425ef Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 20 Jun 2018 11:40:37 +0200 Subject: [PATCH] Use STL list for encoding list This is a lot safer and cleaner. The old code had a fixed size that we didn't properly keep track of. --- common/rfb/CConnection.cxx | 43 +++++++++++++++++++------------------- common/rfb/CMsgWriter.cxx | 9 ++++---- common/rfb/CMsgWriter.h | 4 +++- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index e1c4ba56..b74f2e76 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -568,33 +568,32 @@ void CConnection::requestNewUpdate() void CConnection::updateEncodings() { - int nEncodings = 0; - rdr::U32 encodings[encodingMax+3]; + std::list encodings; if (server.supportsLocalCursor) { - encodings[nEncodings++] = pseudoEncodingCursorWithAlpha; - encodings[nEncodings++] = pseudoEncodingCursor; - encodings[nEncodings++] = pseudoEncodingXCursor; + encodings.push_back(pseudoEncodingCursorWithAlpha); + encodings.push_back(pseudoEncodingCursor); + encodings.push_back(pseudoEncodingXCursor); } if (server.supportsDesktopResize) - encodings[nEncodings++] = pseudoEncodingDesktopSize; + encodings.push_back(pseudoEncodingDesktopSize); if (server.supportsExtendedDesktopSize) - encodings[nEncodings++] = pseudoEncodingExtendedDesktopSize; + encodings.push_back(pseudoEncodingExtendedDesktopSize); if (server.supportsDesktopRename) - encodings[nEncodings++] = pseudoEncodingDesktopName; + encodings.push_back(pseudoEncodingDesktopName); if (server.supportsLEDState) - encodings[nEncodings++] = pseudoEncodingLEDState; + encodings.push_back(pseudoEncodingLEDState); - encodings[nEncodings++] = pseudoEncodingLastRect; - encodings[nEncodings++] = pseudoEncodingContinuousUpdates; - encodings[nEncodings++] = pseudoEncodingFence; - encodings[nEncodings++] = pseudoEncodingQEMUKeyEvent; + encodings.push_back(pseudoEncodingLastRect); + encodings.push_back(pseudoEncodingContinuousUpdates); + encodings.push_back(pseudoEncodingFence); + encodings.push_back(pseudoEncodingQEMUKeyEvent); if (Decoder::supported(preferredEncoding)) { - encodings[nEncodings++] = preferredEncoding; + encodings.push_back(preferredEncoding); } - encodings[nEncodings++] = encodingCopyRect; + encodings.push_back(encodingCopyRect); /* * Prefer encodings in this order: @@ -604,15 +603,15 @@ void CConnection::updateEncodings() if ((preferredEncoding != encodingTight) && Decoder::supported(encodingTight)) - encodings[nEncodings++] = encodingTight; + encodings.push_back(encodingTight); if ((preferredEncoding != encodingZRLE) && Decoder::supported(encodingZRLE)) - encodings[nEncodings++] = encodingZRLE; + encodings.push_back(encodingZRLE); if ((preferredEncoding != encodingHextile) && Decoder::supported(encodingHextile)) - encodings[nEncodings++] = encodingHextile; + encodings.push_back(encodingHextile); // Remaining encodings for (int i = encodingMax; i >= 0; i--) { @@ -625,14 +624,14 @@ void CConnection::updateEncodings() break; default: if ((i != preferredEncoding) && Decoder::supported(i)) - encodings[nEncodings++] = i; + encodings.push_back(i); } } if (server.compressLevel >= 0 && server.compressLevel <= 9) - encodings[nEncodings++] = pseudoEncodingCompressLevel0 + server.compressLevel; + encodings.push_back(pseudoEncodingCompressLevel0 + server.compressLevel); if (server.qualityLevel >= 0 && server.qualityLevel <= 9) - encodings[nEncodings++] = pseudoEncodingQualityLevel0 + server.qualityLevel; + encodings.push_back(pseudoEncodingQualityLevel0 + server.qualityLevel); - writer()->writeSetEncodings(nEncodings, encodings); + writer()->writeSetEncodings(encodings); } diff --git a/common/rfb/CMsgWriter.cxx b/common/rfb/CMsgWriter.cxx index 9fe431ce..d357c976 100644 --- a/common/rfb/CMsgWriter.cxx +++ b/common/rfb/CMsgWriter.cxx @@ -52,13 +52,14 @@ void CMsgWriter::writeSetPixelFormat(const PixelFormat& pf) endMsg(); } -void CMsgWriter::writeSetEncodings(int nEncodings, rdr::U32* encodings) +void CMsgWriter::writeSetEncodings(const std::list encodings) { + std::list::const_iterator iter; startMsg(msgTypeSetEncodings); os->skip(1); - os->writeU16(nEncodings); - for (int i = 0; i < nEncodings; i++) - os->writeU32(encodings[i]); + os->writeU16(encodings.size()); + for (iter = encodings.begin(); iter != encodings.end(); ++iter) + os->writeU32(*iter); endMsg(); } diff --git a/common/rfb/CMsgWriter.h b/common/rfb/CMsgWriter.h index 26251e56..4d533d42 100644 --- a/common/rfb/CMsgWriter.h +++ b/common/rfb/CMsgWriter.h @@ -23,6 +23,8 @@ #ifndef __RFB_CMSGWRITER_H__ #define __RFB_CMSGWRITER_H__ +#include + #include namespace rdr { class OutStream; } @@ -43,7 +45,7 @@ namespace rfb { void writeClientInit(bool shared); void writeSetPixelFormat(const PixelFormat& pf); - void writeSetEncodings(int nEncodings, rdr::U32* encodings); + void writeSetEncodings(const std::list encodings); void writeSetDesktopSize(int width, int height, const ScreenSet& layout); void writeFramebufferUpdateRequest(const Rect& r,bool incremental); -- 2.39.5