diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-09-02 16:17:31 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-11-06 21:06:22 +0100 |
commit | 158eb92c4bc4ec7cdedabd9b192648627513c518 (patch) | |
tree | 61dd50a0bcae0c86459053fcc46c913dee81b701 /common/rdr | |
parent | 067d0e89bf344609ec202f895252411c8fcaec1c (diff) | |
download | tigervnc-158eb92c4bc4ec7cdedabd9b192648627513c518.tar.gz tigervnc-158eb92c4bc4ec7cdedabd9b192648627513c518.zip |
Use static string for exceptions
In preparation for using the built in C++ exception classes, which do
not accept a format string.
Diffstat (limited to 'common/rdr')
-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 |
5 files changed, 30 insertions, 18 deletions
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 */ |