Mikołaj Zalewski : comctl32: tooltips: Remove broken support for non-NULL-terminated strings in TOOLTIPS_GetDispInfo [AW].
Alexandre Julliard
julliard at wine.codeweavers.com
Fri Jul 20 06:02:17 CDT 2007
Module: wine
Branch: master
Commit: f53e31418006ad899716007b41fbcb9ad409a24d
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f53e31418006ad899716007b41fbcb9ad409a24d
Author: Mikołaj Zalewski <mikolaj at zalewski.pl>
Date: Thu Jul 19 16:13:45 2007 +0200
comctl32: tooltips: Remove broken support for non-NULL-terminated strings in TOOLTIPS_GetDispInfo[AW].
---
dlls/comctl32/comctl32.h | 1 +
dlls/comctl32/comctl32undoc.c | 41 +++++++++++++++++++++++++++++++++++++++++
dlls/comctl32/tooltips.c | 21 ++++++---------------
3 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/dlls/comctl32/comctl32.h b/dlls/comctl32/comctl32.h
index e7a3598..5917a9b 100644
--- a/dlls/comctl32/comctl32.h
+++ b/dlls/comctl32/comctl32.h
@@ -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);
diff --git a/dlls/comctl32/comctl32undoc.c b/dlls/comctl32/comctl32undoc.c
index d17436f..6f434a6 100644
--- a/dlls/comctl32/comctl32undoc.c
+++ b/dlls/comctl32/comctl32undoc.c
@@ -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]
diff --git a/dlls/comctl32/tooltips.c b/dlls/comctl32/tooltips.c
index 4e11c5c..9dd1970 100644
--- a/dlls/comctl32/tooltips.c
+++ b/dlls/comctl32/tooltips.c
@@ -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 {
More information about the wine-cvs
mailing list