From f25de739ea359c2843a596457bcd22a28175b7a4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 2 Sep 2024 17:03:10 +0200 Subject: Use what() to access exception description Harmonize with the standard C++ exceptions. --- common/rdr/Exception.h | 2 +- common/rdr/TLSInStream.cxx | 4 ++-- common/rdr/TLSOutStream.cxx | 4 ++-- common/rfb/CConnection.cxx | 2 +- common/rfb/DecodeManager.cxx | 4 ++-- common/rfb/SConnection.cxx | 8 ++++---- common/rfb/VNCSConnectionST.cxx | 32 ++++++++++++++++---------------- 7 files changed, 28 insertions(+), 28 deletions(-) (limited to 'common') diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index c6be8fcc..bdb2061c 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -29,7 +29,7 @@ namespace rdr { Exception(const char* message); Exception(const std::string& message); virtual ~Exception() {} - virtual const char* str() const { return str_; } + virtual const char* what() const { return str_; } private: char str_[256]; }; diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index f8f4fcf9..c0252122 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -57,12 +57,12 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) } catch (EndOfStream&) { return 0; } catch (SocketException& e) { - vlog.error("Failure reading TLS data: %s", e.str()); + vlog.error("Failure reading TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, e.err); self->saved_exception = new SocketException(e); return -1; } catch (Exception& e) { - vlog.error("Failure reading TLS data: %s", e.str()); + vlog.error("Failure reading TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, EINVAL); self->saved_exception = new Exception(e); return -1; diff --git a/common/rdr/TLSOutStream.cxx b/common/rdr/TLSOutStream.cxx index ccb229e1..69d0fe3a 100644 --- a/common/rdr/TLSOutStream.cxx +++ b/common/rdr/TLSOutStream.cxx @@ -47,12 +47,12 @@ ssize_t TLSOutStream::push(gnutls_transport_ptr_t str, const void* data, out->writeBytes((const uint8_t*)data, size); out->flush(); } catch (SocketException& e) { - vlog.error("Failure sending TLS data: %s", e.str()); + vlog.error("Failure sending TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, e.err); self->saved_exception = new SocketException(e); return -1; } catch (Exception& e) { - vlog.error("Failure sending TLS data: %s", e.str()); + vlog.error("Failure sending TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, EINVAL); self->saved_exception = new Exception(e); return -1; diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 61ef7d98..7a9570ad 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -388,7 +388,7 @@ void CConnection::close() try { decoder.flush(); } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + vlog.error("%s", e.what()); } setFramebuffer(nullptr); diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index 269e818d..77beb620 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(format("Error reading rect: %s", e.str())); + throw Exception(format("Error reading rect: %s", e.what())); } stats[encoding].rects++; @@ -250,7 +250,7 @@ void DecodeManager::setThreadException(const rdr::Exception& e) if (threadException != nullptr) return; - threadException = new rdr::Exception(format("Exception on worker thread: %s", e.str())); + threadException = new rdr::Exception(format("Exception on worker thread: %s", e.what())); } void DecodeManager::throwThreadException() diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index 04cf60b9..d96ad178 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -224,7 +224,7 @@ void SConnection::processSecurityType(int secType) state_ = RFBSTATE_SECURITY; ssecurity = security.GetSSecurity(this, secType); } catch (rdr::Exception& e) { - failConnection(e.str()); + failConnection(e.what()); } } @@ -235,11 +235,11 @@ bool SConnection::processSecurityMsg() if (!ssecurity->processMsg()) return false; } catch (AuthFailureException& e) { - vlog.error("AuthFailureException: %s", e.str()); + vlog.error("AuthFailureException: %s", e.what()); state_ = RFBSTATE_SECURITY_FAILURE; // Introduce a slight delay of the authentication failure response // to make it difficult to brute force a password - authFailureMsg = e.str(); + authFailureMsg = e.what(); authFailureTimer.start(100); return true; } @@ -294,7 +294,7 @@ void SConnection::handleAuthFailureTimeout(Timer* /*t*/) } os->flush(); } catch (rdr::Exception& e) { - close(e.str()); + close(e.what()); return; } diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 7dc2a0b8..e0fb69dc 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -130,7 +130,7 @@ void VNCSConnectionST::close(const char* reason) vlog.error("Failed to flush remaining socket data on close"); } } catch (rdr::Exception& e) { - vlog.error("Failed to flush remaining socket data on close: %s", e.str()); + vlog.error("Failed to flush remaining socket data on close: %s", e.what()); } // Just shutdown the socket and mark our state as closing. Eventually the @@ -147,7 +147,7 @@ bool VNCSConnectionST::init() try { initialiseProtocol(); } catch (rdr::Exception& e) { - close(e.str()); + close(e.what()); return false; } return true; @@ -190,7 +190,7 @@ void VNCSConnectionST::processMessages() } catch (rdr::EndOfStream&) { close("Clean disconnection"); } catch (rdr::Exception &e) { - close(e.str()); + close(e.what()); } } @@ -204,7 +204,7 @@ void VNCSConnectionST::flushSocket() if (!sock->outStream().hasBufferedData()) writeFramebufferUpdate(); } catch (rdr::Exception &e) { - close(e.str()); + close(e.what()); } } @@ -253,7 +253,7 @@ void VNCSConnectionST::pixelBufferChange() updates.add_changed(server->getPixelBuffer()->getRect()); writeFramebufferUpdate(); } catch(rdr::Exception &e) { - close(e.str()); + close(e.what()); } } @@ -262,7 +262,7 @@ void VNCSConnectionST::writeFramebufferUpdateOrClose() try { writeFramebufferUpdate(); } catch(rdr::Exception &e) { - close(e.str()); + close(e.what()); } } @@ -272,7 +272,7 @@ void VNCSConnectionST::screenLayoutChangeOrClose(uint16_t reason) screenLayoutChange(reason); writeFramebufferUpdate(); } catch(rdr::Exception &e) { - close(e.str()); + close(e.what()); } } @@ -281,7 +281,7 @@ void VNCSConnectionST::bellOrClose() try { if (state() == RFBSTATE_NORMAL) writer()->writeBell(); } catch(rdr::Exception& e) { - close(e.str()); + close(e.what()); } } @@ -291,7 +291,7 @@ void VNCSConnectionST::setDesktopNameOrClose(const char *name) setDesktopName(name); writeFramebufferUpdate(); } catch(rdr::Exception& e) { - close(e.str()); + close(e.what()); } } @@ -301,7 +301,7 @@ void VNCSConnectionST::setCursorOrClose() setCursor(); writeFramebufferUpdate(); } catch(rdr::Exception& e) { - close(e.str()); + close(e.what()); } } @@ -311,7 +311,7 @@ void VNCSConnectionST::setLEDStateOrClose(unsigned int state) setLEDState(state); writeFramebufferUpdate(); } catch(rdr::Exception& e) { - close(e.str()); + close(e.what()); } } @@ -323,7 +323,7 @@ void VNCSConnectionST::requestClipboardOrClose() if (!rfb::Server::acceptCutText) return; requestClipboard(); } catch(rdr::Exception& e) { - close(e.str()); + close(e.what()); } } @@ -335,7 +335,7 @@ void VNCSConnectionST::announceClipboardOrClose(bool available) if (!rfb::Server::sendCutText) return; announceClipboard(available); } catch(rdr::Exception& e) { - close(e.str()); + close(e.what()); } } @@ -347,7 +347,7 @@ void VNCSConnectionST::sendClipboardDataOrClose(const char* data) if (!rfb::Server::sendCutText) return; sendClipboardData(data); } catch(rdr::Exception& e) { - close(e.str()); + close(e.what()); } } @@ -419,7 +419,7 @@ void VNCSConnectionST::approveConnectionOrClose(bool accept, try { approveConnection(accept, reason); } catch (rdr::Exception& e) { - close(e.str()); + close(e.what()); } } @@ -806,7 +806,7 @@ void VNCSConnectionST::handleTimeout(Timer* t) (t == &losslessTimer)) writeFramebufferUpdate(); } catch (rdr::Exception& e) { - close(e.str()); + close(e.what()); } if (t == &idleTimer) -- cgit v1.2.3