From 17041075b40f39c4e1cabc7b5155e2506fa65ed5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 10 Dec 2017 00:10:38 +0100 Subject: [PATCH] Fix wxLanguageInfo::GetLocaleName() This function could (and did) return completely wrong results because the value of the pointer returned by setlocale() could be (and was) changed by the subsequent call to setlocale() with different arguments. Fix the problem by copying the returned value into wxString immediately, without any intervening setlocale() calls. --- src/common/intl.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 1fc2b8d989..96dd2389d6 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -208,12 +208,17 @@ wxString wxLanguageInfo::GetLocaleName() const const char* const orig = wxSetlocale(LC_ALL, NULL); const char* const ret = TrySetLocale(); - if ( !ret ) - return wxString(); + wxString retval; + if ( ret ) + { + // Note that we must copy the returned value before calling setlocale() + // again as the string "ret" points to can (and, at least under Linux + // with glibc, actually always will) be changed by this call. + retval = ret; + wxSetlocale(LC_ALL, orig); + } - wxSetlocale(LC_ALL, orig); - - return ret; + return retval; } // ----------------------------------------------------------------------------