diff options
-rw-r--r-- | common/network/TcpSocket.cxx | 4 | ||||
-rw-r--r-- | common/rdr/BufferedInStream.cxx | 9 | ||||
-rw-r--r-- | common/rdr/BufferedOutStream.cxx | 9 | ||||
-rw-r--r-- | common/rdr/Exception.cxx | 19 | ||||
-rw-r--r-- | common/rdr/Exception.h | 6 | ||||
-rw-r--r-- | common/rdr/TLSException.cxx | 5 | ||||
-rw-r--r-- | common/rfb/CConnection.cxx | 4 | ||||
-rw-r--r-- | common/rfb/CMsgReader.cxx | 2 | ||||
-rw-r--r-- | common/rfb/CSecurityTLS.cxx | 3 | ||||
-rw-r--r-- | common/rfb/ClientParams.cxx | 3 | ||||
-rw-r--r-- | common/rfb/DecodeManager.cxx | 4 | ||||
-rw-r--r-- | common/rfb/Exception.h | 4 | ||||
-rw-r--r-- | common/rfb/JpegCompressor.cxx | 4 | ||||
-rw-r--r-- | common/rfb/JpegDecompressor.cxx | 4 | ||||
-rw-r--r-- | common/rfb/PixelBuffer.cxx | 75 | ||||
-rw-r--r-- | common/rfb/SConnection.cxx | 40 | ||||
-rw-r--r-- | common/rfb/SConnection.h | 4 | ||||
-rw-r--r-- | common/rfb/SMsgReader.cxx | 2 | ||||
-rw-r--r-- | common/rfb/ServerParams.cxx | 3 | ||||
-rw-r--r-- | common/rfb/TightDecoder.cxx | 3 | ||||
-rw-r--r-- | unix/x0vncserver/XDesktop.cxx | 2 | ||||
-rw-r--r-- | vncviewer/ServerDialog.cxx | 4 | ||||
-rw-r--r-- | vncviewer/parameters.cxx | 38 |
23 files changed, 141 insertions, 110 deletions
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 3f2f0f1f..38cb6eb3 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -663,8 +663,8 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { family = pattern.address.u.sa.sa_family; if (pattern.prefixlen > (family == AF_INET ? 32: 128)) - throw Exception("invalid prefix length for filter address: %u", - pattern.prefixlen); + throw Exception(rfb::format("invalid prefix length for filter address: %u", + pattern.prefixlen)); // Compute mask from address and prefix length memset (&pattern.mask, 0, sizeof (pattern.mask)); diff --git a/common/rdr/BufferedInStream.cxx b/common/rdr/BufferedInStream.cxx index 3c04bafc..204202ec 100644 --- a/common/rdr/BufferedInStream.cxx +++ b/common/rdr/BufferedInStream.cxx @@ -26,6 +26,8 @@ #include <rdr/BufferedInStream.h> #include <rdr/Exception.h> +#include <rfb/util.h> + using namespace rdr; static const size_t DEFAULT_BUF_SIZE = 8192; @@ -63,9 +65,10 @@ void BufferedInStream::ensureSpace(size_t needed) uint8_t* newBuffer; if (needed > MAX_BUF_SIZE) - throw Exception("BufferedInStream overrun: requested size of " - "%lu bytes exceeds maximum of %lu bytes", - (long unsigned)needed, (long unsigned)MAX_BUF_SIZE); + throw Exception(rfb::format("BufferedInStream overrun: requested " + "size of %lu bytes exceeds maximum " + "of %lu bytes", (long unsigned)needed, + (long unsigned)MAX_BUF_SIZE)); newSize = DEFAULT_BUF_SIZE; while (newSize < needed) diff --git a/common/rdr/BufferedOutStream.cxx b/common/rdr/BufferedOutStream.cxx index 0d6a1eb6..f5062bf2 100644 --- a/common/rdr/BufferedOutStream.cxx +++ b/common/rdr/BufferedOutStream.cxx @@ -25,6 +25,7 @@ #include <rdr/BufferedOutStream.h> #include <rdr/Exception.h> +#include <rfb/util.h> using namespace rdr; @@ -138,10 +139,10 @@ void BufferedOutStream::overrun(size_t needed) // We'll need to allocate more buffer space... if (totalNeeded > MAX_BUF_SIZE) - throw Exception("BufferedOutStream overrun: requested size of " - "%lu bytes exceeds maximum of %lu bytes", - (long unsigned)totalNeeded, - (long unsigned)MAX_BUF_SIZE); + throw Exception(rfb::format("BufferedOutStream overrun: requested " + "size of %lu bytes exceeds maximum of " + "%lu bytes", (long unsigned)totalNeeded, + (long unsigned)MAX_BUF_SIZE)); newSize = DEFAULT_BUF_SIZE; while (newSize < totalNeeded) diff --git a/common/rdr/Exception.cxx b/common/rdr/Exception.cxx index 4c99d977..277da533 100644 --- a/common/rdr/Exception.cxx +++ b/common/rdr/Exception.cxx @@ -44,16 +44,19 @@ using namespace rdr; -Exception::Exception(const char *format, ...) { - va_list ap; +Exception::Exception(const char *message) +{ + snprintf(str_, len, "%s", message); +} - va_start(ap, format); - (void) vsnprintf(str_, len, format, ap); - va_end(ap); +Exception::Exception(const std::string& message) +{ + snprintf(str_, len, "%s", message.c_str()); } + GAIException::GAIException(const char* s, int err_) - : Exception("%s", s), err(err_) + : Exception(s), err(err_) { strncat(str_, ": ", len-1-strlen(str_)); #ifdef _WIN32 @@ -78,7 +81,7 @@ GAIException::GAIException(const char* s, int err_) } PosixException::PosixException(const char* s, int err_) - : Exception("%s", s), err(err_) + : Exception(s), err(err_) { strncat(str_, ": ", len-1-strlen(str_)); #ifdef _WIN32 @@ -99,7 +102,7 @@ PosixException::PosixException(const char* s, int err_) #ifdef WIN32 Win32Exception::Win32Exception(const char* s, unsigned err_) - : Exception("%s", s), err(err_) + : Exception(s), err(err_) { strncat(str_, ": ", len-1-strlen(str_)); wchar_t *currStr = new wchar_t[len-strlen(str_)]; diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index c59f7e55..65d3d90a 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -21,13 +21,15 @@ #ifndef __RDR_EXCEPTION_H__ #define __RDR_EXCEPTION_H__ +#include <string> + namespace rdr { struct Exception { enum { len = 256 }; char str_[len]; - Exception(const char *format=nullptr, ...) - __attribute__((__format__ (__printf__, 2, 3))); + Exception(const char* message); + Exception(const std::string& message); virtual ~Exception() {} virtual const char* str() const { return str_; } }; diff --git a/common/rdr/TLSException.cxx b/common/rdr/TLSException.cxx index 0f75a4da..df2701d3 100644 --- a/common/rdr/TLSException.cxx +++ b/common/rdr/TLSException.cxx @@ -24,6 +24,8 @@ #include <rdr/TLSException.h> +#include <rfb/util.h> + #include <string.h> #include <stdio.h> #ifdef HAVE_GNUTLS @@ -34,7 +36,8 @@ using namespace rdr; #ifdef HAVE_GNUTLS TLSException::TLSException(const char* s, int err_) - : Exception("%s: %s (%d)", s, gnutls_strerror(err_), err_), err(err_) + : Exception(rfb::format("%s: %s (%d)", s, gnutls_strerror(err_), err_)), + err(err_) { } #endif /* HAVE_GNUTLS */ diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index b4017dba..61ef7d98 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -185,8 +185,8 @@ bool CConnection::processVersionMsg() vlog.error("Server gave unsupported RFB protocol version %d.%d", server.majorVersion, server.minorVersion); state_ = RFBSTATE_INVALID; - throw Exception("Server gave unsupported RFB protocol version %d.%d", - server.majorVersion, server.minorVersion); + throw Exception(format("Server gave unsupported RFB protocol version %d.%d", + server.majorVersion, server.minorVersion)); } else if (server.beforeVersion(3,7)) { server.setVersion(3,3); } else if (server.afterVersion(3,8)) { diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index 8bcdbfd0..c94ecfd8 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -119,7 +119,7 @@ bool CMsgReader::readMsg() ret = readEndOfContinuousUpdates(); break; default: - throw Exception("Unknown message type %d", currentMsgType); + throw Exception(format("Unknown message type %d", currentMsgType)); } if (ret) diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index 6eeb6a84..8f2ec033 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -344,7 +344,8 @@ void CSecurityTLS::checkSession() gnutls_free(status_str.data); - throw Exception("Invalid server certificate: %s", error.c_str()); + throw Exception(format("Invalid server certificate: %s", + error.c_str())); } err = gnutls_certificate_verification_status_print(status, diff --git a/common/rfb/ClientParams.cxx b/common/rfb/ClientParams.cxx index bc20c3d7..3f80f109 100644 --- a/common/rfb/ClientParams.cxx +++ b/common/rfb/ClientParams.cxx @@ -27,6 +27,7 @@ #include <rfb/ledStates.h> #include <rfb/clipboardTypes.h> #include <rfb/ClientParams.h> +#include <rfb/util.h> using namespace rfb; @@ -160,7 +161,7 @@ uint32_t ClientParams::clipboardSize(unsigned int format) const return clipSizes[i]; } - throw Exception("Invalid clipboard format 0x%x", format); + throw Exception(rfb::format("Invalid clipboard format 0x%x", format)); } void ClientParams::setClipboardCaps(uint32_t flags, const uint32_t* lengths) diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index ef415886..269e818d 100644 --- a/common/rfb/DecodeManager.cxx +++ b/common/rfb/DecodeManager.cxx @@ -149,7 +149,7 @@ bool DecodeManager::decodeRect(const Rect& r, int encoding, if (!decoder->readRect(r, conn->getInStream(), conn->server, bufferStream)) return false; } catch (rdr::Exception& e) { - throw Exception("Error reading rect: %s", e.str()); + throw Exception(format("Error reading rect: %s", e.str())); } stats[encoding].rects++; @@ -250,7 +250,7 @@ void DecodeManager::setThreadException(const rdr::Exception& e) if (threadException != nullptr) return; - threadException = new rdr::Exception("Exception on worker thread: %s", e.str()); + threadException = new rdr::Exception(format("Exception on worker thread: %s", e.str())); } void DecodeManager::throwThreadException() diff --git a/common/rfb/Exception.h b/common/rfb/Exception.h index 773c65fa..3c8a461c 100644 --- a/common/rfb/Exception.h +++ b/common/rfb/Exception.h @@ -24,7 +24,9 @@ namespace rfb { typedef rdr::Exception Exception; struct AuthFailureException : public Exception { AuthFailureException(const char* reason) - : Exception("%s", reason) {} + : Exception(reason) {} + AuthFailureException(std::string& reason) + : Exception(reason) {} }; struct AuthCancelledException : public rfb::Exception { AuthCancelledException() diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx index 42d5c475..49ed4b61 100644 --- a/common/rfb/JpegCompressor.cxx +++ b/common/rfb/JpegCompressor.cxx @@ -127,7 +127,7 @@ JpegCompressor::JpegCompressor(int bufferLen) : MemOutStream(bufferLen) if(setjmp(err->jmpBuffer)) { // this will execute if libjpeg has an error - throw rdr::Exception("%s", err->lastError); + throw rdr::Exception(err->lastError); } jpeg_create_compress(cinfo); @@ -171,7 +171,7 @@ void JpegCompressor::compress(const uint8_t *buf, volatile int stride, jpeg_abort_compress(cinfo); if (srcBufIsTemp && srcBuf) delete[] srcBuf; if (rowPointer) delete[] rowPointer; - throw rdr::Exception("%s", err->lastError); + throw rdr::Exception(err->lastError); } cinfo->image_width = w; diff --git a/common/rfb/JpegDecompressor.cxx b/common/rfb/JpegDecompressor.cxx index 92ef014f..4b3b4db7 100644 --- a/common/rfb/JpegDecompressor.cxx +++ b/common/rfb/JpegDecompressor.cxx @@ -120,7 +120,7 @@ JpegDecompressor::JpegDecompressor(void) if(setjmp(err->jmpBuffer)) { // this will execute if libjpeg has an error - throw rdr::Exception("%s", err->lastError); + throw rdr::Exception(err->lastError); } jpeg_create_decompress(dinfo); @@ -168,7 +168,7 @@ void JpegDecompressor::decompress(const uint8_t *jpegBuf, jpeg_abort_decompress(dinfo); if (dstBufIsTemp && dstBuf) delete[] dstBuf; if (rowPointer) delete[] rowPointer; - throw rdr::Exception("%s", err->lastError); + throw rdr::Exception(err->lastError); } src->pub.next_input_byte = jpegBuf; diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index 0a287544..ca2a5845 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -31,6 +31,7 @@ #include <rfb/Exception.h> #include <rfb/LogWriter.h> #include <rfb/PixelBuffer.h> +#include <rfb/util.h> using namespace rfb; @@ -70,9 +71,10 @@ PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) const const uint8_t* end; if (!r.enclosed_by(getRect())) - throw rfb::Exception("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); data = getBuffer(r, &inStride); @@ -106,9 +108,10 @@ void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf, } if (!r.enclosed_by(getRect())) - throw rfb::Exception("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); if (stride == 0) stride = r.width(); @@ -122,9 +125,9 @@ void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf, void PixelBuffer::setSize(int width, int height) { if ((width < 0) || (width > maxPixelBufferWidth)) - throw rfb::Exception("Invalid PixelBuffer width of %d pixels requested", width); + throw rfb::Exception(rfb::format("Invalid PixelBuffer width of %d pixels requested", width)); if ((height < 0) || (height > maxPixelBufferHeight)) - throw rfb::Exception("Invalid PixelBuffer height of %d pixels requested", height); + throw rfb::Exception(rfb::format("Invalid PixelBuffer height of %d pixels requested", height)); width_ = width; height_ = height; @@ -153,8 +156,10 @@ void ModifiablePixelBuffer::fillRect(const Rect& r, const void* pix) int w, h, b; if (!r.enclosed_by(getRect())) - throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), r.tl.x, r.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); w = r.width(); h = r.height(); @@ -203,9 +208,10 @@ void ModifiablePixelBuffer::imageRect(const Rect& r, uint8_t* end; if (!r.enclosed_by(getRect())) - throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); bytesPerPixel = getPF().bpp/8; @@ -242,15 +248,17 @@ void ModifiablePixelBuffer::copyRect(const Rect &rect, drect = rect; if (!drect.enclosed_by(getRect())) - throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", - drect.width(), drect.height(), - drect.tl.x, drect.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", + drect.width(), drect.height(), + drect.tl.x, drect.tl.y, + width(), height())); srect = drect.translate(move_by_delta.negate()); if (!srect.enclosed_by(getRect())) - throw rfb::Exception("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", - srect.width(), srect.height(), - srect.tl.x, srect.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", + srect.width(), srect.height(), + srect.tl.x, srect.tl.y, + width(), height())); bytesPerPixel = format.bpp/8; @@ -303,9 +311,10 @@ void ModifiablePixelBuffer::imageRect(const PixelFormat& pf, const Rect &dest, int dstStride; if (!dest.enclosed_by(getRect())) - throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", - dest.width(), dest.height(), - dest.tl.x, dest.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", + dest.width(), dest.height(), + dest.tl.x, dest.tl.y, + width(), height())); if (stride == 0) stride = dest.width(); @@ -332,9 +341,10 @@ FullFramePixelBuffer::~FullFramePixelBuffer() {} uint8_t* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride_) { if (!r.enclosed_by(getRect())) - throw rfb::Exception("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); *stride_ = stride; return &data[(r.tl.x + (r.tl.y * stride)) * (format.bpp/8)]; @@ -347,9 +357,10 @@ void FullFramePixelBuffer::commitBufferRW(const Rect& /*r*/) const uint8_t* FullFramePixelBuffer::getBuffer(const Rect& r, int* stride_) const { if (!r.enclosed_by(getRect())) - throw rfb::Exception("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, width(), height()); + throw rfb::Exception(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); *stride_ = stride; return &data[(r.tl.x + (r.tl.y * stride)) * (format.bpp/8)]; @@ -359,13 +370,13 @@ void FullFramePixelBuffer::setBuffer(int width, int height, uint8_t* data_, int stride_) { if ((width < 0) || (width > maxPixelBufferWidth)) - throw rfb::Exception("Invalid PixelBuffer width of %d pixels requested", width); + throw rfb::Exception(rfb::format("Invalid PixelBuffer width of %d pixels requested", width)); if ((height < 0) || (height > maxPixelBufferHeight)) - throw rfb::Exception("Invalid PixelBuffer height of %d pixels requested", height); + throw rfb::Exception(rfb::format("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_); + throw rfb::Exception(rfb::format("Invalid PixelBuffer stride of %d pixels requested", stride_)); if ((width != 0) && (height != 0) && (data_ == nullptr)) - throw rfb::Exception("PixelBuffer requested without a valid memory area"); + throw rfb::Exception(rfb::format("PixelBuffer requested without a valid memory area")); ModifiablePixelBuffer::setSize(width, height); stride = stride_; diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index 905f88a4..04cf60b9 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -133,9 +133,10 @@ bool SConnection::processVersionMsg() if (client.majorVersion != 3) { // unknown protocol version - failConnection("Client needs protocol version %d.%d, server has %d.%d", - client.majorVersion, client.minorVersion, - defaultMajorVersion, defaultMinorVersion); + failConnection(format("Client needs protocol version %d.%d, " + "server has %d.%d", + client.majorVersion, client.minorVersion, + defaultMajorVersion, defaultMinorVersion)); } if (client.minorVersion != 3 && client.minorVersion != 7 && client.minorVersion != 8) { @@ -165,8 +166,9 @@ bool SConnection::processVersionMsg() if (*i == secTypeNone || *i == secTypeVncAuth) break; } if (i == secTypes.end()) { - failConnection("No supported security type for %d.%d client", - client.majorVersion, client.minorVersion); + failConnection(format("No supported security type for " + "%d.%d client", + client.majorVersion, client.minorVersion)); } os->writeU32(*i); @@ -222,7 +224,7 @@ void SConnection::processSecurityType(int secType) state_ = RFBSTATE_SECURITY; ssecurity = security.GetSSecurity(this, secType); } catch (rdr::Exception& e) { - failConnection("%s", e.str()); + failConnection(e.str()); } } @@ -299,33 +301,31 @@ void SConnection::handleAuthFailureTimeout(Timer* /*t*/) close(authFailureMsg.c_str()); } -void SConnection::failConnection(const char* format, ...) +void SConnection::failConnection(const char* message) { - va_list ap; - char str[256]; - - va_start(ap, format); - (void) vsnprintf(str, sizeof(str), format, ap); - va_end(ap); - - vlog.info("Connection failed: %s", str); + vlog.info("Connection failed: %s", message); if (state_ == RFBSTATE_PROTOCOL_VERSION) { if (client.majorVersion == 3 && client.minorVersion == 3) { os->writeU32(0); - os->writeU32(strlen(str)); - os->writeBytes((const uint8_t*)str, strlen(str)); + os->writeU32(strlen(message)); + os->writeBytes((const uint8_t*)message, strlen(message)); os->flush(); } else { os->writeU8(0); - os->writeU32(strlen(str)); - os->writeBytes((const uint8_t*)str, strlen(str)); + os->writeU32(strlen(message)); + os->writeBytes((const uint8_t*)message, strlen(message)); os->flush(); } } state_ = RFBSTATE_INVALID; - throw Exception("%s", str); + throw Exception(message); +} + +void SConnection::failConnection(const std::string& message) +{ + failConnection(message.c_str()); } void SConnection::setAccessRights(AccessRights ar) diff --git a/common/rfb/SConnection.h b/common/rfb/SConnection.h index 0a11f67b..886972af 100644 --- a/common/rfb/SConnection.h +++ b/common/rfb/SConnection.h @@ -219,8 +219,8 @@ namespace rfb { // failConnection() prints a message to the log, sends a connection // failed message to the client (if possible) and throws an // Exception. - void failConnection(const char* format, ...) - __attribute__((__format__ (__printf__, 2, 3))); + void failConnection(const char* message); + void failConnection(const std::string& message); void setState(stateEnum s) { state_ = s; } diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index 9ddea53d..5b1b0eaa 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -464,7 +464,7 @@ bool SMsgReader::readQEMUMessage() ret = readQEMUKeyEvent(); break; default: - throw Exception("unknown QEMU submessage type %d", subType); + throw Exception(format("unknown QEMU submessage type %d", subType)); } if (!ret) { diff --git a/common/rfb/ServerParams.cxx b/common/rfb/ServerParams.cxx index 9f6f5307..2a8d3a8e 100644 --- a/common/rfb/ServerParams.cxx +++ b/common/rfb/ServerParams.cxx @@ -25,6 +25,7 @@ #include <rfb/Exception.h> #include <rfb/ledStates.h> #include <rfb/ServerParams.h> +#include <rfb/util.h> using namespace rfb; @@ -99,7 +100,7 @@ uint32_t ServerParams::clipboardSize(unsigned int format) const return clipSizes[i]; } - throw Exception("Invalid clipboard format 0x%x", format); + throw Exception(rfb::format("Invalid clipboard format 0x%x", format)); } void ServerParams::setClipboardCaps(uint32_t flags, const uint32_t* lengths) diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx index 807f71a5..89d2e839 100644 --- a/common/rfb/TightDecoder.cxx +++ b/common/rfb/TightDecoder.cxx @@ -36,6 +36,7 @@ #include <rfb/PixelBuffer.h> #include <rfb/TightConstants.h> #include <rfb/TightDecoder.h> +#include <rfb/util.h> using namespace rfb; @@ -110,7 +111,7 @@ bool TightDecoder::readRect(const Rect& r, rdr::InStream* is, int palSize = 0; if (r.width() > TIGHT_MAX_WIDTH) - throw Exception("TightDecoder: too large rectangle (%d pixels)", r.width()); + throw Exception(format("TightDecoder: too large rectangle (%d pixels)", r.width())); // Possible palette if ((comp_ctl & tightExplicitFilter) != 0) { diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx index fd19dd71..1dc76718 100644 --- a/unix/x0vncserver/XDesktop.cxx +++ b/unix/x0vncserver/XDesktop.cxx @@ -98,7 +98,7 @@ XDesktop::XDesktop(Display* dpy_, Geometry *geometry_) if (!XkbQueryExtension(dpy, &xkbOpcode, &xkbEventBase, &xkbErrorBase, &major, &minor)) { vlog.error("XKEYBOARD extension not present"); - throw Exception(); + throw Exception("XKEYBOARD extension not present"); } XkbSelectEvents(dpy, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx index 8622fff1..7b334bca 100644 --- a/vncviewer/ServerDialog.cxx +++ b/vncviewer/ServerDialog.cxx @@ -382,8 +382,8 @@ void ServerDialog::loadServerHistory() if (len == (sizeof(line) - 1)) { fclose(f); - throw Exception(_("Failed to read line %d in file %s: %s"), - lineNr, filepath, _("Line too long")); + throw Exception(format(_("Failed to read line %d in file %s: %s"), + lineNr, filepath, _("Line too long"))); } if ((len > 0) && (line[len-1] == '\n')) { diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index c75cad8b..2beae930 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -465,8 +465,8 @@ static void saveToReg(const char* servername) { setKeyString("ServerName", servername, &hKey); } catch (Exception& e) { RegCloseKey(hKey); - throw Exception(_("Failed to save \"%s\": %s"), - "ServerName", e.str()); + throw Exception(format(_("Failed to save \"%s\": %s"), + "ServerName", e.str())); } for (size_t i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { @@ -482,8 +482,8 @@ static void saveToReg(const char* servername) { } } catch (Exception& e) { RegCloseKey(hKey); - throw Exception(_("Failed to save \"%s\": %s"), - parameterArray[i]->getName(), e.str()); + throw Exception(format(_("Failed to save \"%s\": %s"), + parameterArray[i]->getName(), e.str())); } } @@ -495,8 +495,9 @@ static void saveToReg(const char* servername) { removeValue(readOnlyParameterArray[i]->getName(), &hKey); } catch (Exception& e) { RegCloseKey(hKey); - throw Exception(_("Failed to remove \"%s\": %s"), - readOnlyParameterArray[i]->getName(), e.str()); + throw Exception(format(_("Failed to remove \"%s\": %s"), + readOnlyParameterArray[i]->getName(), + e.str())); } } @@ -656,8 +657,9 @@ void saveViewerParameters(const char *filename, const char *servername) { if (!encodeValue(servername, encodingBuffer, buffersize)) { fclose(f); - throw Exception(_("Failed to save \"%s\": %s"), - "ServerName", _("Could not encode parameter")); + throw Exception(format(_("Failed to save \"%s\": %s"), + "ServerName", + _("Could not encode parameter"))); } fprintf(f, "ServerName=%s\n", encodingBuffer); @@ -666,9 +668,9 @@ void saveViewerParameters(const char *filename, const char *servername) { if (!encodeValue(*(StringParameter*)param, encodingBuffer, buffersize)) { fclose(f); - throw Exception(_("Failed to save \"%s\": %s"), - param->getName(), - _("Could not encode parameter")); + throw Exception(format(_("Failed to save \"%s\": %s"), + param->getName(), + _("Could not encode parameter"))); } fprintf(f, "%s=%s\n", ((StringParameter*)param)->getName(), encodingBuffer); } else if (dynamic_cast<IntParameter*>(param) != nullptr) { @@ -677,9 +679,9 @@ void saveViewerParameters(const char *filename, const char *servername) { fprintf(f, "%s=%d\n", ((BoolParameter*)param)->getName(), (int)*(BoolParameter*)param); } else { fclose(f); - throw Exception(_("Failed to save \"%s\": %s"), - param->getName(), - _("Unknown parameter type")); + throw Exception(format(_("Failed to save \"%s\": %s"), + param->getName(), + _("Unknown parameter type"))); } } fclose(f); @@ -775,8 +777,8 @@ char* loadViewerParameters(const char *filename) { if (strlen(line) == (sizeof(line) - 1)) { fclose(f); - throw Exception(_("Failed to read line %d in file %s: %s"), - lineNr, filepath, _("Line too long")); + throw Exception(format(_("Failed to read line %d in file %s: %s"), + lineNr, filepath, _("Line too long"))); } // Make sure that the first line of the file has the file identifier string @@ -785,8 +787,8 @@ char* loadViewerParameters(const char *filename) { continue; fclose(f); - throw Exception(_("Configuration file %s is in an invalid format"), - filepath); + throw Exception(format(_("Configuration file %s is in an invalid " + "format"), filepath)); } // Skip empty lines and comments |