comctl32: tooltips: Remove broken support for non-NULL-terminated strings in TOOLTIPS_GetDispInfo[AW].

This commit is contained in:
Mikołaj Zalewski 2007-07-19 16:13:45 +02:00 committed by Alexandre Julliard
parent 31be5005c6
commit f53e314180
3 changed files with 48 additions and 15 deletions

View file

@ -148,6 +148,7 @@ VOID COMCTL32_RefreshSysColors(void);
void COMCTL32_DrawInsertMark(HDC hDC, const RECT *lpRect, COLORREF clrInsertMark, BOOL bHorizontal);
void COMCTL32_EnsureBitmapSize(HBITMAP *pBitmap, int cxMinWidth, int cyMinHeight, COLORREF crBackground);
INT Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen);
INT Str_GetPtrAtoW (LPCSTR lpSrc, LPWSTR lpDest, INT nMaxLen);
BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc);
BOOL Str_SetPtrWtoA (LPSTR *lppDest, LPCWSTR lpSrc);

View file

@ -922,6 +922,47 @@ INT Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
return len;
}
/**************************************************************************
* Str_GetPtrAtoW [internal]
*
* Converts a multibyte string into a unicode string
*
* PARAMS
* lpSrc [I] Pointer to the multibyte source string
* lpDest [O] Pointer to caller supplied storage for the unicode string
* nMaxLen [I] Size, in characters, of the destination buffer
*
* RETURNS
* Length, in characters, of the converted string.
*/
INT Str_GetPtrAtoW (LPCSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
{
INT len;
TRACE("(%s %p %d)\n", debugstr_a(lpSrc), lpDest, nMaxLen);
if (!lpDest && lpSrc)
return MultiByteToWideChar(CP_ACP, 0, lpSrc, -1, 0, 0);
if (nMaxLen == 0)
return 0;
if (lpSrc == NULL) {
lpDest[0] = '\0';
return 0;
}
len = MultiByteToWideChar(CP_ACP, 0, lpSrc, -1, 0, 0);
if (len >= nMaxLen)
len = nMaxLen - 1;
MultiByteToWideChar(CP_ACP, 0, lpSrc, -1, lpDest, len);
lpDest[len] = '\0';
return len;
}
/**************************************************************************
* Str_SetPtrAtoW [internal]

View file

@ -336,17 +336,11 @@ static void TOOLTIPS_GetDispInfoA(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO
infoPtr->szTipText[0] = '\0';
}
else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : -1;
MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, max_len,
infoPtr->szTipText, INFOTIPSIZE);
Str_GetPtrAtoW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
if (ttnmdi.uFlags & TTF_DI_SETITEM) {
INT len = MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText,
max_len, NULL, 0);
toolPtr->hinst = 0;
toolPtr->lpszText = Alloc (len * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, ttnmdi.lpszText, -1,
toolPtr->lpszText, len);
toolPtr->lpszText = NULL;
Str_SetPtrW(&toolPtr->lpszText, infoPtr->szTipText);
}
}
else {
@ -385,14 +379,11 @@ static void TOOLTIPS_GetDispInfoW(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO
infoPtr->szTipText[0] = '\0';
}
else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ?
sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : INFOTIPSIZE-1;
lstrcpynW(infoPtr->szTipText, ttnmdi.lpszText, max_len);
Str_GetPtrW(ttnmdi.lpszText, infoPtr->szTipText, INFOTIPSIZE);
if (ttnmdi.uFlags & TTF_DI_SETITEM) {
INT len = max(strlenW(ttnmdi.lpszText), max_len);
toolPtr->hinst = 0;
toolPtr->lpszText = Alloc ((len+1) * sizeof(WCHAR));
memcpy(toolPtr->lpszText, ttnmdi.lpszText, (len+1) * sizeof(WCHAR));
toolPtr->lpszText = NULL;
Str_SetPtrW(&toolPtr->lpszText, infoPtr->szTipText);
}
}
else {