diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2019-02-15 08:52:43 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2021-11-23 22:48:28 +0100 |
commit | 24f9b416227da7fc4e381e1c3f20123ad6530da5 (patch) | |
tree | d62f1fdea87f99e688b2c7539f5d4e13fc82704b /src | |
parent | 95b8c9df84109dd8960bbdaa1bc1f5121100e024 (diff) |
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)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Utilities/StringFormat.h | 10 |
1 files changed, 9 insertions, 1 deletions
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<typename Format, typename... Args> inline std::string StringFormat(Format&& fmt, Args&&... args) { - return fmt::sprintf(std::forward<Format>(fmt), std::forward<Args>(args)...); + try + { + return fmt::sprintf(std::forward<Format>(fmt), std::forward<Args>(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. |