From ccb0a03d1f9335888188b82ddb9741a705a08a70 Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Fri, 1 Jul 2005 15:38:39 +0000 Subject: [PATCH] GetDlgItemText should always try to NULL terminate the string. --- dlls/user/dialog.c | 2 ++ dlls/user/tests/dialog.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/dlls/user/dialog.c b/dlls/user/dialog.c index 119c051df8b..a9ad30e4152 100644 --- a/dlls/user/dialog.c +++ b/dlls/user/dialog.c @@ -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 ); } diff --git a/dlls/user/tests/dialog.c b/dlls/user/tests/dialog.c index 37a72dca13d..d55eef4eaed 100644 --- a/dlls/user/tests/dialog.c +++ b/dlls/user/tests/dialog.c @@ -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(); } -- 2.11.4.GIT