Fixed subtle memory allocation bug. Mysterious crashes in glibc may go away now.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2002-11-18 23:12:11 +00:00
parent bae090fcff
commit 73a0aac054

View File

@@ -666,7 +666,7 @@ bool wxLocale::Init(int language, int flags)
wxString name = info->Description; wxString name = info->Description;
wxString canonical = info->CanonicalName; wxString canonical = info->CanonicalName;
wxString locale; wxString locale;
const wxChar *retloc; wxString retloc;
// Set the locale: // Set the locale:
#if defined(__UNIX__) && !defined(__WXMAC__) #if defined(__UNIX__) && !defined(__WXMAC__)
@@ -677,12 +677,12 @@ bool wxLocale::Init(int language, int flags)
retloc = wxSetlocale(LC_ALL, locale); retloc = wxSetlocale(LC_ALL, locale);
if (retloc == NULL) if (retloc.empty())
{ {
// Some C libraries don't like xx_YY form and require xx only // Some C libraries don't like xx_YY form and require xx only
retloc = wxSetlocale(LC_ALL, locale.Mid(0,2)); retloc = wxSetlocale(LC_ALL, locale.Mid(0,2));
} }
if (retloc == NULL) if (retloc.empty())
{ {
// Some C libraries (namely glibc) still use old ISO 639, // Some C libraries (namely glibc) still use old ISO 639,
// so will translate the abbrev for them // so will translate the abbrev for them
@@ -692,13 +692,13 @@ bool wxLocale::Init(int language, int flags)
else if (mid == wxT("yi")) locale = wxT("ji") + locale.Mid(3); else if (mid == wxT("yi")) locale = wxT("ji") + locale.Mid(3);
retloc = wxSetlocale(LC_ALL, locale); retloc = wxSetlocale(LC_ALL, locale);
} }
if (retloc == NULL) if (retloc.empty())
{ {
// (This time, we changed locale in previous if-branch, so try again.) // (This time, we changed locale in previous if-branch, so try again.)
// Some C libraries don't like xx_YY form and require xx only // Some C libraries don't like xx_YY form and require xx only
retloc = wxSetlocale(LC_ALL, locale.Mid(0,2)); retloc = wxSetlocale(LC_ALL, locale.Mid(0,2));
} }
if (retloc == NULL) if (retloc.empty())
{ {
wxLogError(wxT("Cannot set locale to '%s'."), locale.c_str()); wxLogError(wxT("Cannot set locale to '%s'."), locale.c_str());
return FALSE; return FALSE;
@@ -745,7 +745,7 @@ bool wxLocale::Init(int language, int flags)
else else
retloc = wxSetlocale(LC_ALL, wxEmptyString); retloc = wxSetlocale(LC_ALL, wxEmptyString);
if (retloc == NULL) if (retloc.empty())
{ {
wxLogError(wxT("Cannot set locale to language %s."), name.c_str()); wxLogError(wxT("Cannot set locale to language %s."), name.c_str());
return FALSE; return FALSE;
@@ -756,7 +756,7 @@ bool wxLocale::Init(int language, int flags)
return FALSE; return FALSE;
#endif #endif
return Init(name, canonical, wxString(retloc), return Init(name, canonical, retloc,
(flags & wxLOCALE_LOAD_DEFAULT) != 0, (flags & wxLOCALE_LOAD_DEFAULT) != 0,
(flags & wxLOCALE_CONV_ENCODING) != 0); (flags & wxLOCALE_CONV_ENCODING) != 0);
} }