Commit ccb0a03d authored by Robert Shearman's avatar Robert Shearman Committed by Alexandre Julliard

GetDlgItemText should always try to NULL terminate the string.

parent 07dd5a7e
...@@ -1295,6 +1295,7 @@ BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString ) ...@@ -1295,6 +1295,7 @@ BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
*/ */
INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len ) 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, return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
len, (LPARAM)str ); len, (LPARAM)str );
} }
...@@ -1305,6 +1306,7 @@ INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len ) ...@@ -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 ) 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, return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
len, (LPARAM)str ); len, (LPARAM)str );
} }
......
...@@ -849,6 +849,18 @@ static void InitialFocusTest (void) ...@@ -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) START_TEST(dialog)
{ {
...@@ -860,4 +872,5 @@ START_TEST(dialog) ...@@ -860,4 +872,5 @@ START_TEST(dialog)
IsDialogMessageWTest(); IsDialogMessageWTest();
WM_NEXTDLGCTLTest(); WM_NEXTDLGCTLTest();
InitialFocusTest(); InitialFocusTest();
test_GetDlgItemText();
} }
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