- 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); 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 static inline DWORD
DWORDfromString(const WCHAR *pszString) DWORDfromString(const WCHAR *pszString)
{ {

View file

@ -318,7 +318,7 @@ InputList_Add(LOCALE_LIST_NODE *pLocale, LAYOUT_LIST_NODE *pLayout)
if (len > 0) if (len > 0)
{ {
szIndicator[len - 1] = 0; szIndicator[len - 1] = 0;
pInput->pszIndicator = DuplicateString(szIndicator); pInput->pszIndicator = _wcsdup(szIndicator);
} }
} }
@ -447,7 +447,7 @@ InputList_Create(VOID)
if (len > 0) if (len > 0)
{ {
szIndicator[len - 1] = 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)); ZeroMemory(pNew, sizeof(LAYOUT_LIST_NODE));
pNew->pszName = DuplicateString(pszName); pNew->pszName = _wcsdup(pszName);
if (pNew->pszName == NULL) if (pNew->pszName == NULL)
{ {
free(pNew); free(pNew);
@ -153,10 +153,8 @@ LayoutList_Create(VOID)
(LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS && (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS &&
szBuffer[0] == L'@') szBuffer[0] == L'@')
{ {
WCHAR szPath[MAX_PATH];
WCHAR *pBuffer; WCHAR *pBuffer;
WCHAR *pIndex; WCHAR *pIndex;
INT iIndex;
/* Move to the position after the character "@" */ /* Move to the position after the character "@" */
pBuffer = szBuffer + 1; pBuffer = szBuffer + 1;
@ -164,6 +162,11 @@ LayoutList_Create(VOID)
/* Get a pointer to the beginning ",-" */ /* Get a pointer to the beginning ",-" */
pIndex = wcsstr(pBuffer, L",-"); pIndex = wcsstr(pBuffer, L",-");
if (pIndex != NULL)
{
WCHAR szPath[MAX_PATH];
INT iIndex;
/* Convert the number in the string after the ",-" */ /* Convert the number in the string after the ",-" */
iIndex = _wtoi(pIndex + 2); iIndex = _wtoi(pIndex + 2);
@ -203,6 +206,11 @@ LayoutList_Create(VOID)
} }
else else
{ {
goto NotTranslated;
}
}
else
{
NotTranslated: NotTranslated:
dwSize = sizeof(szBuffer); dwSize = sizeof(szBuffer);

View file

@ -28,7 +28,7 @@ LocaleList_Append(DWORD dwId, const WCHAR *pszName)
ZeroMemory(pNew, sizeof(LOCALE_LIST_NODE)); ZeroMemory(pNew, sizeof(LOCALE_LIST_NODE));
pNew->pszName = DuplicateString(pszName); pNew->pszName = _wcsdup(pszName);
if (pNew->pszName == NULL) if (pNew->pszName == NULL)
{ {
free(pNew); free(pNew);