Merge pull request #4881 from ace20022/json_fix
authorjmarshallnz <jcmarsha@gmail.com>
Wed, 11 Jun 2014 21:19:25 +0000 (09:19 +1200)
committerJonathan Marshall <jmarshall@xbmc.org>
Sun, 15 Jun 2014 04:25:15 +0000 (16:25 +1200)
[Fix][JSON] Fix re-set locale after using yajl

xbmc/utils/JSONVariantWriter.cpp

index 9fbacc1..300fd1c 100644 (file)
@@ -39,8 +39,12 @@ string CJSONVariantWriter::Write(const CVariant &value, bool compact)
 
   // Set locale to classic ("C") to ensure valid JSON numbers
   const char *currentLocale = setlocale(LC_NUMERIC, NULL);
+  std::string backupLocale;
   if (currentLocale != NULL)
+  {
+    backupLocale = currentLocale;
     setlocale(LC_NUMERIC, "C");
+  }
 
   if (InternalWrite(g, value))
   {
@@ -57,8 +61,8 @@ string CJSONVariantWriter::Write(const CVariant &value, bool compact)
   }
 
   // Re-set locale to what it was before using yajl
-  if (currentLocale != NULL)
-    setlocale(LC_NUMERIC, currentLocale);
+  if (!backupLocale.empty())
+    setlocale(LC_NUMERIC, backupLocale.c_str());
 
   yajl_gen_clear(g);
   yajl_gen_free(g);