From e1827d08cc619f91bb62ac0eac2cff457ca4c9d6 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 13 Nov 2020 20:28:24 +0100 Subject: [PATCH] Fix CURLException::what(). --- src/curl_wrapper.cpp | 16 ++++++++++------ src/curl_wrapper.hpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index a981b83..7255854 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -222,15 +222,19 @@ void CURLWrapper::check(const CURLcode code) } } -const char *CURLException::what() noexcept +const char *CURLException::what() const noexcept { - if (!_error_message.empty()) + // NOTE: The string has to be static, or it'll vanish before it can be + // used. Couldn't find good documentation on that. + static string error_string; + error_string = _error_message; + if (!error_string.empty()) { - _error_message = ": " + _error_message; + error_string = " – " + error_string; } - _error_message = "libcurl_error: " + std::to_string(error_code) - + _error_message; - return _error_message.c_str(); + error_string = "libcurl error: " + std::to_string(error_code) + + error_string; + return error_string.c_str(); } } // namespace curl_wrapper diff --git a/src/curl_wrapper.hpp b/src/curl_wrapper.hpp index 0c3b6f2..68997b2 100644 --- a/src/curl_wrapper.hpp +++ b/src/curl_wrapper.hpp @@ -233,7 +233,7 @@ public: * * @since 0.1.0 */ - [[nodiscard]] const char *what() noexcept; + [[nodiscard]] const char *what() const noexcept override; private: string _error_message;