From 372bb6ec31e26908966ff553b782c9a24a07db6a Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 1 Jan 2018 23:56:35 +0000 Subject: Make InspIRCd::Format return std::string instead of const char*. Using the latter is problematic as if you don't copy the return value before calling Format again your formatted message will be overwritten by something else. This bug was observed in m_callerid where InspIRCd::Format was being used for formatting two arguments the latter of which was being overwritten with the former. We could have preserved the return type and just copied the string but then callers would have had to deallocate the string once they have finished with it which is an undesirabable burden to put on callers. --- include/modules/sql.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'include/modules/sql.h') diff --git a/include/modules/sql.h b/include/modules/sql.h index dd33fc676..01adbb42e 100644 --- a/include/modules/sql.h +++ b/include/modules/sql.h @@ -132,7 +132,7 @@ class SQL::Error { private: /** The custom error message if one has been specified. */ - const char* message; + const std::string message; public: /** The code which represents this error. */ @@ -142,8 +142,7 @@ class SQL::Error * @param c A code which represents this error. */ Error(ErrorCode c) - : message(NULL) - , code(c) + : code(c) { } @@ -151,7 +150,7 @@ class SQL::Error * @param c A code which represents this error. * @param m A custom error message. */ - Error(ErrorCode c, const char* m) + Error(ErrorCode c, const std::string m) : message(m) , code(c) { @@ -160,8 +159,8 @@ class SQL::Error /** Retrieves the error message. */ const char* ToString() const { - if (message) - return message; + if (!message.empty()) + return message.c_str(); switch (code) { -- cgit v1.3.1-10-gc9f91