From c5ba8fbb12f8533b07c6f2d798b135bb1a931338 Mon Sep 17 00:00:00 2001 From: Dmitry Chapyshev Date: Thu, 18 Aug 2016 10:31:42 +0000 Subject: [PATCH] [INPUT] - 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 | 17 ----------- reactos/dll/cpl/input/input_list.c | 4 +-- reactos/dll/cpl/input/layout_list.c | 44 +++++++++++++++++------------ reactos/dll/cpl/input/locale_list.c | 2 +- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/reactos/dll/cpl/input/input.h b/reactos/dll/cpl/input/input.h index bf2d06df14b..eda9db913fe 100644 --- a/reactos/dll/cpl/input/input.h +++ b/reactos/dll/cpl/input/input.h @@ -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) { diff --git a/reactos/dll/cpl/input/input_list.c b/reactos/dll/cpl/input/input_list.c index e8f7226e707..f4ed7f7b8dc 100644 --- a/reactos/dll/cpl/input/input_list.c +++ b/reactos/dll/cpl/input/input_list.c @@ -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); } } } diff --git a/reactos/dll/cpl/input/layout_list.c b/reactos/dll/cpl/input/layout_list.c index 2dafdd64c19..f0820688d02 100644 --- a/reactos/dll/cpl/input/layout_list.c +++ b/reactos/dll/cpl/input/layout_list.c @@ -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); - - pIndex[0] = 0; - - if (ExpandEnvironmentStringsW(pBuffer, szPath, ARRAYSIZE(szPath)) != 0) + if (pIndex != NULL) { - HANDLE hHandle; + WCHAR szPath[MAX_PATH]; + INT iIndex; - hHandle = LoadLibraryW(szPath); - if (hHandle != NULL) + /* Convert the number in the string after the ",-" */ + iIndex = _wtoi(pIndex + 2); + + pIndex[0] = 0; + + if (ExpandEnvironmentStringsW(pBuffer, szPath, ARRAYSIZE(szPath)) != 0) { - INT iLength = LoadStringW(hHandle, iIndex, szBuffer, ARRAYSIZE(szBuffer)); + HANDLE hHandle; - FreeLibrary(hHandle); - - if (iLength != 0) + hHandle = LoadLibraryW(szPath); + if (hHandle != NULL) { - DWORD dwLayoutId = DWORDfromString(szLayoutId); + INT iLength = LoadStringW(hHandle, iIndex, szBuffer, ARRAYSIZE(szBuffer)); - LayoutList_AppendNode(dwLayoutId, dwSpecialId, szBuffer); + FreeLibrary(hHandle); + + if (iLength != 0) + { + DWORD dwLayoutId = DWORDfromString(szLayoutId); + + LayoutList_AppendNode(dwLayoutId, dwSpecialId, szBuffer); + } + else + { + goto NotTranslated; + } } else { diff --git a/reactos/dll/cpl/input/locale_list.c b/reactos/dll/cpl/input/locale_list.c index 77b11891890..4c415af7703 100644 --- a/reactos/dll/cpl/input/locale_list.c +++ b/reactos/dll/cpl/input/locale_list.c @@ -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);