WM_GETTEXT in DefWindowProc

Duane Clark dclark at akamail.com
Tue Mar 19 13:48:58 CST 2002


Some applications expect a null termination in the first character if 
the string being retrieved by WM_GETTEXT is empty.

As with all my patches (including the one yesterday), this patch is 
released under the old X11 style wine license.

Log message:
	On WM_GETTEXT, terminate the lparam buffer even if string is empty.
-------------- next part --------------
Index: windows/defwnd.c
===================================================================
RCS file: /home/wine/wine/windows/defwnd.c,v
retrieving revision 1.73
diff -u -r1.73 defwnd.c
--- windows/defwnd.c	10 Mar 2002 00:18:37 -0000	1.73
+++ windows/defwnd.c	19 Mar 2002 19:40:29 -0000
@@ -796,12 +796,17 @@
     case WM_GETTEXT:
         {
             WND *wndPtr = WIN_GetPtr( hwnd );
-            if (wParam && wndPtr && wndPtr->text)
+            if (wParam && wndPtr)
             {
                 LPSTR dest = (LPSTR)lParam;
-                if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
-                                          dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
-                result = strlen( dest );
+                if (wndPtr->text)
+                {
+                    if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
+                                            dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
+                    result = strlen( dest );
+                }
+                else
+                    dest[0] = '\0';
             }
             WIN_ReleasePtr( wndPtr );
         }
@@ -930,11 +935,16 @@
     case WM_GETTEXT:
         {
             WND *wndPtr = WIN_GetPtr( hwnd );
-            if (wParam && wndPtr && wndPtr->text)
+            if (wParam && wndPtr)
             {
                 LPWSTR dest = (LPWSTR)lParam;
-                lstrcpynW( dest, wndPtr->text, wParam );
-                result = strlenW( dest );
+                if (wndPtr->text)
+                {
+                    lstrcpynW( dest, wndPtr->text, wParam );
+                    result = strlenW( dest );
+                }
+                else
+                    dest[0] = '\0';
             }
             WIN_ReleasePtr( wndPtr );
         }


More information about the wine-patches mailing list