PATCH: more string buffer for LB_GETTEXTL

Marcus Meissner meissner at suse.de
Thu Mar 10 09:55:21 CST 2005


Hi,

Updated as requested ... I don't really like that approach ;)

Ciao, Marcus

Changelog:
	Use 512 byte buffer for buffer of LB_GETTEXT and CB_GETLBTEXT.
	Added testcase with > 256 byte string in listbox.

Index: windows/winproc.c
===================================================================
RCS file: /home/wine/wine/windows/winproc.c,v
retrieving revision 1.128
diff -u -r1.128 winproc.c
--- windows/winproc.c	15 Feb 2005 21:51:06 -0000	1.128
+++ windows/winproc.c	10 Mar 2005 15:51:21 -0000
@@ -766,7 +766,7 @@
 
     case LB_GETTEXT:		    /* FIXME: fixed sized buffer */
         { if ( WINPROC_TestLBForStr( hwnd ))
-	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
+	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 512 * sizeof(WCHAR) + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
             *plparam = (LPARAM)ptr;
@@ -791,7 +791,7 @@
 
     case CB_GETLBTEXT:    /* FIXME: fixed sized buffer */
         { if ( WINPROC_TestCBForStr( hwnd ))
-          { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
+          { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 512 * sizeof(WCHAR) + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
             *plparam = (LPARAM)ptr;
@@ -1061,7 +1061,7 @@
 
     case LB_GETTEXT:			/* FIXME: fixed sized buffer */
         { if ( WINPROC_TestLBForStr( hwnd ))
-	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
+	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 512 + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
             *plparam = (LPARAM)ptr;
@@ -1087,7 +1087,7 @@
 
     case CB_GETLBTEXT:		/* FIXME: fixed sized buffer */
         { if ( WINPROC_TestCBForStr( hwnd ))
-	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
+	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 512 + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
             *plparam = (LPARAM)ptr;
@@ -2782,7 +2782,7 @@
     case LB_GETTEXT:
         if ( WINPROC_TestLBForStr( hwnd ))
         {
-            LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
+            LPSTR str = HeapAlloc( GetProcessHeap(), 0, 512 ); /* FIXME: fixed sized buffer */
             if (!str) return -1;
             *pmsg16    = LB_GETTEXT16;
             *plparam   = (LPARAM)MapLS(str);
@@ -2791,7 +2791,7 @@
     case CB_GETLBTEXT:
         if ( WINPROC_TestCBForStr( hwnd ))
         {
-            LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
+            LPSTR str = HeapAlloc( GetProcessHeap(), 0, 512 ); /* FIXME: fixed sized buffer */
             if (!str) return -1;
             *pmsg16    = CB_GETLBTEXT16;
             *plparam   = (LPARAM)MapLS(str);
Index: dlls/user/painting.c
===================================================================
RCS file: /home/wine/wine/dlls/user/painting.c,v
retrieving revision 1.22
diff -u -r1.22 painting.c
--- dlls/user/painting.c	8 Mar 2005 19:26:57 -0000	1.22
+++ dlls/user/painting.c	10 Mar 2005 15:51:21 -0000
@@ -354,8 +354,13 @@
             TRACE( "%p not repainted properly, erasing\n", child );
             if ((hrgn = send_ncpaint( child, NULL, &erase_flags )))
             {
-                send_erase( child, erase_flags, hrgn, &rect, NULL );
+                BOOL ret;
+
+                ret = send_erase( child, erase_flags, hrgn, &rect, NULL );
                 DeleteObject( hrgn );
+                if (!ret) {
+                   FIXME("send_erase returned FALSE after second try erase.\n");
+		}
             }
             prev = 0;
         }
Index: dlls/user/tests/listbox.c
===================================================================
RCS file: /home/wine/wine/dlls/user/tests/listbox.c,v
retrieving revision 1.6
diff -u -r1.6 listbox.c
--- dlls/user/tests/listbox.c	2 Feb 2005 19:10:59 -0000	1.6
+++ dlls/user/tests/listbox.c	10 Mar 2005 15:51:21 -0000
@@ -30,6 +30,13 @@
 #define REDRAW
 #endif
 
+static const char *strings[4] = {
+  "First added",
+  "Second added",
+  "Third added",
+  "Fourth added which is very long because at some time we only had a 256 byte character buffer and that was overflowing in one of those applications that had a common dialog file open box and tried to add a 300 characters long custom filter string which of course the code did not like and crashed. Just make sure this string is longer than 256 characters."
+};
+
 HWND
 create_listbox (DWORD add_style)
 {
@@ -39,9 +46,10 @@
                             NULL, NULL, NULL, 0);
 
   assert (handle);
-  SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "First added");
-  SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "Second added");
-  SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "Third added");
+  SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[0]);
+  SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[1]);
+  SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[2]);
+  SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[3]);
 
 #ifdef VISIBLE
   ShowWindow (handle, SW_SHOW);
@@ -119,6 +127,7 @@
   struct listbox_stat answer;
   HWND hLB=create_listbox (test.prop.add_style);
   RECT second_item;
+  int i;
 
   listbox_query (hLB, &answer);
   listbox_ok (test, init, answer);
@@ -140,6 +149,24 @@
   SendMessage (hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
   listbox_query (hLB, &answer);
   listbox_ok (test, sel, answer);
+
+  for (i=0;i<4;i++) {
+	DWORD size = SendMessage (hLB, LB_GETTEXTLEN, i, 0);
+	CHAR *txt;
+	WCHAR *txtw;
+
+	txt = HeapAlloc (GetProcessHeap(), 0, size+1);
+	SendMessageA(hLB, LB_GETTEXT, i, (LPARAM)txt);
+        ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
+
+	txtw = HeapAlloc (GetProcessHeap(), 0, 2*size+2);
+	SendMessageW(hLB, LB_GETTEXT, i, (LPARAM)txtw);
+	WideCharToMultiByte( CP_ACP, 0, txtw, -1, txt, size, NULL, NULL );
+        ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
+
+	HeapFree (GetProcessHeap(), 0, txtw);
+	HeapFree (GetProcessHeap(), 0, txt);
+  }
   
   WAIT;
   DestroyWindow (hLB);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20050310/98966b2c/attachment.pgp


More information about the wine-patches mailing list