]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 771772 ] Crashes when setting icon tooltip longer than 63 characters
authorJulian Smart <julian@anthemion.co.uk>
Thu, 11 Sep 2003 10:39:57 +0000 (10:39 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 11 Sep 2003 10:39:57 +0000 (10:39 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23506 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/window.cpp

index a40b07091228800dd7760245c3ebe982ee614836..b0fa0492c15e7193076692275557c121b7258494 100644 (file)
@@ -3118,9 +3118,33 @@ bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
         // in Unicode mode this is just what we need
         ttText->lpszText = (wxChar *)ttip.c_str();
 #else // !Unicode
+/*
         MultiByteToWideChar(CP_ACP, 0, ttip, ttip.length()+1,
                             (wchar_t *)ttText->szText,
                             sizeof(ttText->szText) / sizeof(wchar_t));
+*/
+        // Fix by dimitrishortcut: see patch 771772
+
+        // FIXME: szText has a max of 80 bytes, so limit the tooltip string
+        // length accordingly. Ideally lpszText should be used, but who
+        // would be responsible for freeing the buffer?
+
+        // Maximum length of a tip is 39 characters. 39 is 80/2 minus 1 byte
+        // needed for NULL character.
+        size_t tipLength = wxMin(ttip.Len(), 39);
+
+        // Convert to WideChar without adding the NULL character. The NULL
+        // character is added afterwards (Could have used ttip.Left(tipLength)
+        // and a cchMultiByte parameter of tipLength+1, but this is more
+        //efficient.
+        ::MultiByteToWideChar(CP_ACP, 0, ttip, tipLength,
+                             (wchar_t *)ttText->szText,
+                             sizeof(ttText->szText) / sizeof(wchar_t));
+
+        // Add the NULL character.
+        ttText->szText[tipLength*2+0] = '\0';
+        ttText->szText[tipLength*2+1] = '\0';
+
 #endif // Unicode/!Unicode
     }