From 24f9b416227da7fc4e381e1c3f20123ad6530da5 Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Fri, 15 Feb 2019 08:52:43 +0100 Subject: Shared/Utilities: Handle string format exceptions Handle StringFormat() exceptions in case of malformed string format to avoid causing unhandled exception crashes (cherry picked from commit c79811de4fbf2b22cd74f55853516c7fc307055f) --- src/common/Utilities/StringFormat.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/common/Utilities/StringFormat.h') diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h index dd990c637e2..ba0adacc888 100644 --- a/src/common/Utilities/StringFormat.h +++ b/src/common/Utilities/StringFormat.h @@ -26,7 +26,15 @@ namespace Trinity template inline std::string StringFormat(Format&& fmt, Args&&... args) { - return fmt::sprintf(std::forward(fmt), std::forward(args)...); + try + { + return fmt::sprintf(std::forward(fmt), std::forward(args)...); + } + catch (const fmt::FormatError& formatError) + { + std::string error = "An error occurred formatting string \"" + std::string(fmt) + "\" : " + std::string(formatError.what()); + return error; + } } /// Returns true if the given char pointer is null. -- cgit v1.2.3