diff options
Diffstat (limited to 'misc.h')
-rw-r--r-- | misc.h | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -548,13 +548,20 @@ inline void SecureWipeArray(T *buf, size_t n) } // this function uses wcstombs(), which assumes that setlocale() has been called -static std::string StringNarrow(const wchar_t *str) +static std::string StringNarrow(const wchar_t *str, bool throwOnError = true) { #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable: 4996) // 'wcstombs': This function or variable may be unsafe. #endif size_t size = wcstombs(NULL, str, 0); + if (size == -1) + { + if (throwOnError) + throw InvalidArgument("StringNarrow: wcstombs() call failed"); + else + return std::string(); + } std::string result(size, 0); wcstombs(&result[0], str, size); return result; |