From 7d40084d44640753b389864bc95db583775e953e Mon Sep 17 00:00:00 2001 From: Karlson2k Date: Thu, 5 Feb 2015 22:33:43 +0300 Subject: [PATCH] [win32] JSONVariantWriter::Write(): use wide string version of setlocale() to prevent crash on win32 --- xbmc/utils/JSONVariantWriter.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/xbmc/utils/JSONVariantWriter.cpp b/xbmc/utils/JSONVariantWriter.cpp index 43ddcea46d78b..0d0a7aa32f8a0 100644 --- a/xbmc/utils/JSONVariantWriter.cpp +++ b/xbmc/utils/JSONVariantWriter.cpp @@ -33,6 +33,7 @@ string CJSONVariantWriter::Write(const CVariant &value, bool compact) yajl_gen_config(g, yajl_gen_indent_string, "\t"); // Set locale to classic ("C") to ensure valid JSON numbers +#ifndef TARGET_WINDOWS const char *currentLocale = setlocale(LC_NUMERIC, NULL); std::string backupLocale; if (currentLocale != NULL && (currentLocale[0] != 'C' || currentLocale[1] != 0)) @@ -40,6 +41,15 @@ string CJSONVariantWriter::Write(const CVariant &value, bool compact) backupLocale = currentLocale; setlocale(LC_NUMERIC, "C"); } +#else // TARGET_WINDOWS + const wchar_t* const currentLocale = _wsetlocale(LC_NUMERIC, NULL); + std::wstring backupLocale; + if (currentLocale != NULL && (currentLocale[0] != L'C' || currentLocale[1] != 0)) + { + backupLocale = currentLocale; + _wsetlocale(LC_NUMERIC, L"C"); + } +#endif // TARGET_WINDOWS if (InternalWrite(g, value)) { @@ -51,8 +61,13 @@ string CJSONVariantWriter::Write(const CVariant &value, bool compact) } // Re-set locale to what it was before using yajl +#ifndef TARGET_WINDOWS if (!backupLocale.empty()) setlocale(LC_NUMERIC, backupLocale.c_str()); +#else // TARGET_WINDOWS + if (!backupLocale.empty()) + _wsetlocale(LC_NUMERIC, backupLocale.c_str()); +#endif // TARGET_WINDOWS yajl_gen_clear(g); yajl_gen_free(g);