From 8fd67d96e0d1487ff79fd24d5e8fb1fa8c304ec3 Mon Sep 17 00:00:00 2001 From: Christoph von Wittich Date: Sun, 29 Jul 2007 19:04:03 +0000 Subject: [PATCH] Fix bug in IsValidLocale(), GetNumberFormatW(), GetCurrencyFormatW() patch by Zavyalov Alexey (reactos at ilimschool dot ru) See issue #2374 for more details. svn path=/trunk/; revision=28020 --- reactos/dll/win32/kernel32/misc/lang.c | 4 +- reactos/dll/win32/kernel32/misc/lcformat.c | 69 +++++++++++++++++++++- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/reactos/dll/win32/kernel32/misc/lang.c b/reactos/dll/win32/kernel32/misc/lang.c index dc99898fa15..f1912e0cc84 100644 --- a/reactos/dll/win32/kernel32/misc/lang.c +++ b/reactos/dll/win32/kernel32/misc/lang.c @@ -1504,8 +1504,7 @@ IsValidLocale(LCID Locale, } ValueData = (PWSTR)&KeyInfo->Data[0]; - if ((dwFlags & LCID_INSTALLED) && - (KeyInfo->Type == REG_SZ) && + if ((KeyInfo->Type == REG_SZ) && (KeyInfo->DataLength == 2 * sizeof(WCHAR)) && (ValueData[0] == L'1')) { @@ -1849,3 +1848,4 @@ VerLanguageNameW ( } + diff --git a/reactos/dll/win32/kernel32/misc/lcformat.c b/reactos/dll/win32/kernel32/misc/lcformat.c index f6e6b91e566..ba7a6a9d383 100644 --- a/reactos/dll/win32/kernel32/misc/lcformat.c +++ b/reactos/dll/win32/kernel32/misc/lcformat.c @@ -91,6 +91,53 @@ static RTL_CRITICAL_SECTION_DEBUG NLS_FormatsCS_debug = }; static RTL_CRITICAL_SECTION NLS_FormatsCS = { &NLS_FormatsCS_debug, -1, 0, 0, 0, 0 }; +/************************************************************************** + * NLS_isSystemLocale + * + * Return TRUE, if locale is system-type + */ +BOOL NLS_isSystemLocale(LCID lcid) +{ + if(lcid == LOCALE_SYSTEM_DEFAULT || + lcid == LOCALE_NEUTRAL || + lcid == LOCALE_USER_DEFAULT) + { + return TRUE; + } + return FALSE; +} + +/************************************************************************** + * NLS_isSystemLocale + * + * Return default system or user locale + */ +LCID NLS_getDefaultLocale(LCID lcid) +{ + LCID lcidTmp; + + DPRINT("Called NLS_getDefaultLocale(0x%04lx)\n", lcid); + + switch(lcid) + { + case LOCALE_SYSTEM_DEFAULT: + NtQueryDefaultLocale(FALSE, &lcidTmp); + return lcidTmp; + break; + + case LOCALE_USER_DEFAULT: + case LOCALE_NEUTRAL: + NtQueryDefaultLocale(TRUE, &lcidTmp); + return lcidTmp; + break; + + default: + DPRINT1("FIXME: unknown system lcid\n"); + } + + return lcid; +} + /************************************************************************** * NLS_GetLocaleNumber * @@ -968,8 +1015,17 @@ INT WINAPI GetNumberFormatW(LCID lcid, DWORD dwFlags, TRACE("(0x%04lx,0x%08lx,%S,%p,%p,%d)\n", lcid, dwFlags, lpszValue, lpFormat, lpNumberStr, cchOut); + if(NLS_isSystemLocale(lcid)) + { + lcid = NLS_getDefaultLocale(lcid); + } + else if(!IsValidLocale(lcid, 0)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + if (!lpszValue || cchOut < 0 || (cchOut > 0 && !lpNumberStr) || - !IsValidLocale(lcid, 0) || (lpFormat && (dwFlags || !lpFormat->lpDecimalSep || !lpFormat->lpThousandSep))) { GetNumberFormatW_Error: @@ -1334,8 +1390,17 @@ INT WINAPI GetCurrencyFormatW(LCID lcid, DWORD dwFlags, TRACE("(0x%04lx,0x%08lx,%S,%p,%p,%d)\n", lcid, dwFlags, lpszValue, lpFormat, lpCurrencyStr, cchOut); + if(NLS_isSystemLocale(lcid)) + { + lcid = NLS_getDefaultLocale(lcid); + } + else if(!IsValidLocale(lcid, 0)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + if (!lpszValue || cchOut < 0 || (cchOut > 0 && !lpCurrencyStr) || - !IsValidLocale(lcid, 0) || (lpFormat && (dwFlags || !lpFormat->lpDecimalSep || !lpFormat->lpThousandSep || !lpFormat->lpCurrencySymbol || lpFormat->NegativeOrder > 15 || lpFormat->PositiveOrder > 3)))