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. --- src/helperfuncs.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index c29e7d2cc..e331ba9dc 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -331,7 +331,7 @@ unsigned long InspIRCd::Duration(const std::string &str) return total + subtotal; } -const char* InspIRCd::Format(va_list &vaList, const char* formatString) +std::string InspIRCd::Format(va_list& vaList, const char* formatString) { static std::vector formatBuffer(1024); @@ -351,12 +351,12 @@ const char* InspIRCd::Format(va_list &vaList, const char* formatString) formatBuffer.resize(formatBuffer.size() * 2); } - return &formatBuffer[0]; + return std::string(&formatBuffer[0]); } -const char* InspIRCd::Format(const char* formatString, ...) +std::string InspIRCd::Format(const char* formatString, ...) { - const char* ret; + std::string ret; VAFORMAT(ret, formatString, formatString); return ret; } -- cgit v1.2.3