mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
Use the C locale for non-Windows CharArrayFromFormatV() and StringFromFormat()
The Windows implementations of CharArrayFromFormatV() and StringFromFormat() use the "C"/".1252" locale instead of the user locale (using _vsnprintf_l). On non-Windows, the user locale was used. This leads to bugs on non-Windows: the Overclock parameter was serialised with the user locale ("0,279322" in some locale) and was interpreted back as "0" (because the C locale is used for parsing the string). Make non-Windows CharArrayFromFormatV() and StringFromFormat() consistent with their Windows counterpart. The locale code is not enables for Android:: uselocale is only available since API 21 and API 21 only supports C and C.UTF-8.
This commit is contained in:
parent
3c475b91ea
commit
266d50c811
@ -22,9 +22,18 @@
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <iconv.h>
|
||||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(ANDROID)
|
||||
static locale_t GetCLocale()
|
||||
{
|
||||
static locale_t c_locale = newlocale(LC_ALL_MASK, "C", NULL);
|
||||
return c_locale;
|
||||
}
|
||||
#endif
|
||||
|
||||
// faster than sscanf
|
||||
bool AsciiToHex(const std::string& _szValue, u32& result)
|
||||
{
|
||||
@ -77,7 +86,13 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
|
||||
c_locale = _create_locale(LC_ALL, ".1252");
|
||||
writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
|
||||
#else
|
||||
#if !defined(ANDROID)
|
||||
locale_t previousLocale = uselocale(GetCLocale());
|
||||
#endif
|
||||
writtenCount = vsnprintf(out, outsize, format, args);
|
||||
#if !defined(ANDROID)
|
||||
uselocale(previousLocale);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (writtenCount > 0 && writtenCount < outsize)
|
||||
@ -112,8 +127,14 @@ std::string StringFromFormatV(const char* format, va_list args)
|
||||
std::string temp = buf;
|
||||
delete[] buf;
|
||||
#else
|
||||
#if !defined(ANDROID)
|
||||
locale_t previousLocale = uselocale(GetCLocale());
|
||||
#endif
|
||||
if (vasprintf(&buf, format, args) < 0)
|
||||
ERROR_LOG(COMMON, "Unable to allocate memory for string");
|
||||
#if !defined(ANDROID)
|
||||
uselocale(previousLocale);
|
||||
#endif
|
||||
|
||||
std::string temp = buf;
|
||||
free(buf);
|
||||
|
Loading…
Reference in New Issue
Block a user