Avoid using stale nl_langinfo() pointer

See #17813
This commit is contained in:
Paul Cornett
2017-03-02 07:48:08 -08:00
parent 2278bb0dfa
commit a0cb7c1291

View File

@@ -824,15 +824,11 @@ wxString wxLocale::GetSystemEncodingName()
// to Unix98) // to Unix98)
char *oldLocale = strdup(setlocale(LC_CTYPE, NULL)); char *oldLocale = strdup(setlocale(LC_CTYPE, NULL));
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
const char *alang = nl_langinfo(CODESET); encname = wxString::FromAscii(nl_langinfo(CODESET));
setlocale(LC_CTYPE, oldLocale); setlocale(LC_CTYPE, oldLocale);
free(oldLocale); free(oldLocale);
if ( alang ) if (encname.empty())
{
encname = wxString::FromAscii( alang );
}
else // nl_langinfo() failed
#endif // HAVE_LANGINFO_H #endif // HAVE_LANGINFO_H
{ {
// if we can't get at the character set directly, try to see if it's in // if we can't get at the character set directly, try to see if it's in