GetDlgItemText should always try to NULL terminate the string.

This commit is contained in:
Robert Shearman 2005-07-01 15:38:39 +00:00 committed by Alexandre Julliard
parent 07dd5a7e86
commit ccb0a03d1f
2 changed files with 15 additions and 0 deletions

View File

@ -1295,6 +1295,7 @@ BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
*/
INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
{
if (str && (len > 0)) str[0] = '\0';
return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
len, (LPARAM)str );
}
@ -1305,6 +1306,7 @@ INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
*/
INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
{
if (str && (len > 0)) str[0] = '\0';
return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
len, (LPARAM)str );
}

View File

@ -849,6 +849,18 @@ static void InitialFocusTest (void)
}
}
static void test_GetDlgItemText(void)
{
char string[64];
BOOL ret;
strcpy(string, "Overwrite Me");
ret = GetDlgItemTextA(NULL, 0, string, sizeof(string)/sizeof(string[0]));
ok(!ret, "GetDlgItemText(NULL) shouldn't have succeeded\n");
ok(string[0] == '\0', "string retrieved using GetDlgItemText should have been NULL terminated\n");
}
START_TEST(dialog)
{
@ -860,4 +872,5 @@ START_TEST(dialog)
IsDialogMessageWTest();
WM_NEXTDLGCTLTest();
InitialFocusTest();
test_GetDlgItemText();
}