changeset 1397:2ccf7eacedf5

Safety checks in dw_bitmapbutton_new*() on Windows and OS/2.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 27 Nov 2011 11:01:01 +0000
parents 117cc38a3799
children 152e3c8916de
files os2/dw.c win/dw.c
diffstat 2 files changed, 32 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/os2/dw.c	Sun Nov 27 10:54:08 2011 +0000
+++ b/os2/dw.c	Sun Nov 27 11:01:01 2011 +0000
@@ -5714,7 +5714,8 @@
                     NULL,
                     NULL);
 
-   strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
+   if(text)
+      strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
    blah->oldproc = WinSubclassWindow(tmp, _BtProc);
 
    WinSetWindowPtr(tmp, QWP_USER, blah);
@@ -5811,7 +5812,8 @@
       }
    }
 
-   strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
+   if(text)
+      strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
    blah->oldproc = WinSubclassWindow(tmp, _BtProc);
 
    WinSetWindowPtr(tmp, QWP_USER, blah);
@@ -5909,7 +5911,8 @@
       }
    }
 
-   strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
+   if(text)
+      strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
    blah->oldproc = WinSubclassWindow(tmp, _BtProc);
 
    WinSetWindowPtr(tmp, QWP_USER, blah);
--- a/win/dw.c	Sun Nov 27 10:54:08 2011 +0000
+++ b/win/dw.c	Sun Nov 27 11:01:01 2011 +0000
@@ -3529,29 +3529,32 @@
 
 void _create_tooltip(HWND handle, char *text)
 {
-    /* Create a tooltip. */
-    HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST,
-        TOOLTIPS_CLASS, NULL,
-        WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
-        CW_USEDEFAULT, CW_USEDEFAULT,
-        CW_USEDEFAULT, CW_USEDEFAULT,
-        handle, NULL, DWInstance,NULL);
-    TOOLINFO ti = { 0 };
-
-    SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
-
-    /* Set up "tool" information.
-     * In this case, the "tool" is the entire parent window.
-     */
-    ti.cbSize = sizeof(TOOLINFO);
-    ti.uFlags = TTF_SUBCLASS;
-    ti.hwnd = handle;
-    ti.hinst = DWInstance;
-    ti.lpszText = text;
-    ti.rect.right = ti.rect.bottom = 500;
-
-    /* Associate the tooltip with the "tool" window. */
-    SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
+    if(text)
+    {
+        /* Create a tooltip. */
+        HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST,
+            TOOLTIPS_CLASS, NULL,
+            WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
+            CW_USEDEFAULT, CW_USEDEFAULT,
+            CW_USEDEFAULT, CW_USEDEFAULT,
+            handle, NULL, DWInstance,NULL);
+        TOOLINFO ti = { 0 };
+
+        SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+
+        /* Set up "tool" information.
+         * In this case, the "tool" is the entire parent window.
+         */
+        ti.cbSize = sizeof(TOOLINFO);
+        ti.uFlags = TTF_SUBCLASS;
+        ti.hwnd = handle;
+        ti.hinst = DWInstance;
+        ti.lpszText = text;
+        ti.rect.right = ti.rect.bottom = 500;
+
+        /* Associate the tooltip with the "tool" window. */
+        SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
+    }
 }
 
 #ifndef GDIPLUS