[INPUT]
authorDmitry Chapyshev <dmitry@reactos.org>
Thu, 18 Aug 2016 10:31:42 +0000 (10:31 +0000)
committerDmitry Chapyshev <dmitry@reactos.org>
Thu, 18 Aug 2016 10:31:42 +0000 (10:31 +0000)
- Use _wcsdup instead internal DuplicateString
- Check of the returned value of the wcsstr function is added

svn path=/trunk/; revision=72301

reactos/dll/cpl/input/input.h
reactos/dll/cpl/input/input_list.c
reactos/dll/cpl/input/layout_list.c
reactos/dll/cpl/input/locale_list.c

index bf2d06d..eda9db9 100644 (file)
@@ -75,23 +75,6 @@ INT_PTR CALLBACK
 ChangeKeySeqDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
 
-static inline WCHAR*
-DuplicateString(const WCHAR *pszString)
-{
-    WCHAR *pszDuplicate;
-    size_t size;
-
-    size = (wcslen(pszString) + 1) * sizeof(WCHAR);
-
-    pszDuplicate = (WCHAR*) malloc(size);
-    if (pszDuplicate != NULL)
-    {
-        StringCbCopyW(pszDuplicate, size, pszString);
-    }
-
-    return pszDuplicate;
-}
-
 static inline DWORD
 DWORDfromString(const WCHAR *pszString)
 {
index e8f7226..f4ed7f7 100644 (file)
@@ -318,7 +318,7 @@ InputList_Add(LOCALE_LIST_NODE *pLocale, LAYOUT_LIST_NODE *pLayout)
         if (len > 0)
         {
             szIndicator[len - 1] = 0;
-            pInput->pszIndicator = DuplicateString(szIndicator);
+            pInput->pszIndicator = _wcsdup(szIndicator);
         }
     }
 
@@ -447,7 +447,7 @@ InputList_Create(VOID)
                         if (len > 0)
                         {
                             szIndicator[len - 1] = 0;
-                            pInput->pszIndicator = DuplicateString(szIndicator);
+                            pInput->pszIndicator = _wcsdup(szIndicator);
                         }
                     }
                 }
index 2dafdd6..f082068 100644 (file)
@@ -28,7 +28,7 @@ LayoutList_AppendNode(DWORD dwId, DWORD dwSpecialId, const WCHAR *pszName)
 
     ZeroMemory(pNew, sizeof(LAYOUT_LIST_NODE));
 
-    pNew->pszName = DuplicateString(pszName);
+    pNew->pszName = _wcsdup(pszName);
     if (pNew->pszName == NULL)
     {
         free(pNew);
@@ -153,10 +153,8 @@ LayoutList_Create(VOID)
                                          (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS &&
                         szBuffer[0] == L'@')
                     {
-                        WCHAR szPath[MAX_PATH];
                         WCHAR *pBuffer;
                         WCHAR *pIndex;
-                        INT iIndex;
 
                         /* Move to the position after the character "@" */
                         pBuffer = szBuffer + 1;
@@ -164,27 +162,37 @@ LayoutList_Create(VOID)
                         /* Get a pointer to the beginning ",-" */
                         pIndex = wcsstr(pBuffer, L",-");
 
-                        /* Convert the number in the string after the ",-" */
-                        iIndex = _wtoi(pIndex + 2);
+                        if (pIndex != NULL)
+                        {
+                            WCHAR szPath[MAX_PATH];
+                            INT iIndex;
 
-                        pIndex[0] = 0;
+                            /* Convert the number in the string after the ",-" */
+                            iIndex = _wtoi(pIndex + 2);
 
-                        if (ExpandEnvironmentStringsW(pBuffer, szPath, ARRAYSIZE(szPath)) != 0)
-                        {
-                            HANDLE hHandle;
+                            pIndex[0] = 0;
 
-                            hHandle = LoadLibraryW(szPath);
-                            if (hHandle != NULL)
+                            if (ExpandEnvironmentStringsW(pBuffer, szPath, ARRAYSIZE(szPath)) != 0)
                             {
-                                INT iLength = LoadStringW(hHandle, iIndex, szBuffer, ARRAYSIZE(szBuffer));
-
-                                FreeLibrary(hHandle);
+                                HANDLE hHandle;
 
-                                if (iLength != 0)
+                                hHandle = LoadLibraryW(szPath);
+                                if (hHandle != NULL)
                                 {
-                                    DWORD dwLayoutId = DWORDfromString(szLayoutId);
+                                    INT iLength = LoadStringW(hHandle, iIndex, szBuffer, ARRAYSIZE(szBuffer));
+
+                                    FreeLibrary(hHandle);
+
+                                    if (iLength != 0)
+                                    {
+                                        DWORD dwLayoutId = DWORDfromString(szLayoutId);
 
-                                    LayoutList_AppendNode(dwLayoutId, dwSpecialId, szBuffer);
+                                        LayoutList_AppendNode(dwLayoutId, dwSpecialId, szBuffer);
+                                    }
+                                    else
+                                    {
+                                        goto NotTranslated;
+                                    }
                                 }
                                 else
                                 {
index 77b1189..4c415af 100644 (file)
@@ -28,7 +28,7 @@ LocaleList_Append(DWORD dwId, const WCHAR *pszName)
 
     ZeroMemory(pNew, sizeof(LOCALE_LIST_NODE));
 
-    pNew->pszName = DuplicateString(pszName);
+    pNew->pszName = _wcsdup(pszName);
     if (pNew->pszName == NULL)
     {
         free(pNew);