Commit af54602c authored by Marcus Meissner's avatar Marcus Meissner Committed by Alexandre Julliard

Use 512 byte buffer for buffer of LB_GETTEXT and CB_GETLBTEXT.

Added testcase with > 256 byte string in listbox.
parent 555eaaf8
......@@ -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 @@ create_listbox (DWORD add_style)
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 @@ check (const struct listbox_test test)
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);
......@@ -141,6 +150,24 @@ check (const struct listbox_test test)
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);
}
......
......@@ -766,7 +766,7 @@ INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plpara
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 @@ INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plpara
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 @@ static INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM
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 @@ static INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM
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 @@ INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
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 @@ INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment