[ros-diffs] [cwittich] 28020: Fix bug in IsValidLocale(), GetNumberFormatW(), GetCurrencyFormatW() patch by Zavyalov Alexey (reactos at ilimschool dot ru) See issue #2374 for more details.

cwittich at svn.reactos.org cwittich at svn.reactos.org
Sun Jul 29 21:04:03 CEST 2007


Author: cwittich
Date: Sun Jul 29 23:04:03 2007
New Revision: 28020

URL: http://svn.reactos.org/svn/reactos?rev=28020&view=rev
Log:
Fix bug in IsValidLocale(), GetNumberFormatW(), GetCurrencyFormatW()
patch by Zavyalov Alexey (reactos at ilimschool dot ru)
See issue #2374 for more details.

Modified:
    trunk/reactos/dll/win32/kernel32/misc/lang.c
    trunk/reactos/dll/win32/kernel32/misc/lcformat.c

Modified: trunk/reactos/dll/win32/kernel32/misc/lang.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/lang.c?rev=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/lang.c (original)
+++ trunk/reactos/dll/win32/kernel32/misc/lang.c Sun Jul 29 23:04:03 2007
@@ -1504,8 +1504,7 @@
     }
 
   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 @@
 }
 
 
+

Modified: trunk/reactos/dll/win32/kernel32/misc/lcformat.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/lcformat.c?rev=28020&r1=28019&r2=28020&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/lcformat.c (original)
+++ trunk/reactos/dll/win32/kernel32/misc/lcformat.c Sun Jul 29 23:04:03 2007
@@ -90,6 +90,53 @@
       0, 0, 0, 0
 };
 static RTL_CRITICAL_SECTION NLS_FormatsCS = { &NLS_FormatsCS_debug, -1, 0, 0, 0, 0 };
+
+/**************************************************************************
+ * NLS_isSystemLocale <internal>
+ *
+ * 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 <internal>
+ *
+ * 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 <internal>
@@ -968,8 +1015,17 @@
   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 @@
   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)))




More information about the Ros-diffs mailing list