Skip to content

Commit

Permalink
CJSONVariantWriter: fix possible NULL pointer dereferencing
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese authored and davilla committed Mar 11, 2013
1 parent d6f3d21 commit 32b2e2b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions xbmc/utils/JSONVariantWriter.cpp
Expand Up @@ -38,8 +38,9 @@ string CJSONVariantWriter::Write(const CVariant &value, bool compact)
#endif

// Set locale to classic ("C") to ensure valid JSON numbers
std::string currentLocale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C");
const char *currentLocale = setlocale(LC_NUMERIC, NULL);
if (currentLocale != NULL)
setlocale(LC_NUMERIC, "C");

if (InternalWrite(g, value))
{
Expand All @@ -56,7 +57,8 @@ string CJSONVariantWriter::Write(const CVariant &value, bool compact)
}

// Re-set locale to what it was before using yajl
setlocale(LC_NUMERIC, currentLocale.c_str());
if (currentLocale != NULL)
setlocale(LC_NUMERIC, currentLocale);

yajl_gen_clear(g);
yajl_gen_free(g);
Expand Down

0 comments on commit 32b2e2b

Please sign in to comment.