- Use _wcsdup instead internal DuplicateString
- Check of the returned value of the wcsstr function is added

svn path=/trunk/; revision=72301
This commit is contained in:
Dmitry Chapyshev 2016-08-18 10:31:42 +00:00
parent 9b71c6be30
commit c5ba8fbb12
4 changed files with 29 additions and 38 deletions

View 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)
{

View 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);
}
}
}

View 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);
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
{

View 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);