Use 512 byte buffer for buffer of LB_GETTEXT and CB_GETLBTEXT.

Added testcase with > 256 byte string in listbox.
This commit is contained in:
Marcus Meissner 2005-03-10 17:17:22 +00:00 committed by Alexandre Julliard
parent 555eaaf8c2
commit af54602c7a
2 changed files with 36 additions and 9 deletions

View File

@ -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);
}

View File

@ -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);