From 390a248e0649cf5cc4c4e8a476f0747bc204c3ba Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Wed, 26 Aug 2009 08:50:39 -0700 Subject: [PATCH] comctl32: Return the number of characters copied in WM_GETTEXT even if the buffer is too small. --- dlls/comctl32/status.c | 11 ++++++++--- dlls/comctl32/tests/status.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/dlls/comctl32/status.c b/dlls/comctl32/status.c index 11a977d376..d6b627a979 100644 --- a/dlls/comctl32/status.c +++ b/dlls/comctl32/status.c @@ -1016,12 +1016,17 @@ STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf) len = strlenW (infoPtr->parts[0].text); - if (size > len) { + if (!size) + return len; + else if (size > len) { strcpyW (buf, infoPtr->parts[0].text); return len; } - - return -1; + else { + memcpy (buf, infoPtr->parts[0].text, (size - 1) * sizeof(WCHAR)); + buf[size - 1] = 0; + return size - 1; + } } diff --git a/dlls/comctl32/tests/status.c b/dlls/comctl32/tests/status.c index f1cbda47f0..28df50fe49 100644 --- a/dlls/comctl32/tests/status.c +++ b/dlls/comctl32/tests/status.c @@ -466,6 +466,34 @@ static void test_status_ownerdraw(void) SetWindowLongPtr( g_hMainWnd, GWLP_WNDPROC, (LONG_PTR)g_wndproc_saved ); } +static void test_gettext(void) +{ + HWND hwndStatus = CreateWindow(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE, + 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL); + char buf[5]; + int r; + + r = SendMessage(hwndStatus, SB_SETTEXT, 0, (LPARAM)"Text"); + expect(TRUE, r); + r = SendMessage(hwndStatus, WM_GETTEXTLENGTH, 0, 0); + expect(4, r); + /* A size of 0 returns the length of the text */ + r = SendMessage(hwndStatus, WM_GETTEXT, 0, 0); + expect(4, r); + /* A size of 1 only stores the NULL terminator */ + buf[0] = 0xa; + r = SendMessage(hwndStatus, WM_GETTEXT, 1, (LPARAM)buf); + expect(0, r); + ok(!buf[0], "expected empty buffer\n"); + /* A size of 2 returns a length 1 */ + r = SendMessage(hwndStatus, WM_GETTEXT, 2, (LPARAM)buf); + expect(1, r); + r = SendMessage(hwndStatus, WM_GETTEXT, sizeof(buf), (LPARAM)buf); + expect(4, r); + ok(!strcmp(buf, "Text"), "expected Text, got %s\n", buf); + DestroyWindow(hwndStatus); +} + START_TEST(status) { hinst = GetModuleHandleA(NULL); @@ -483,4 +511,5 @@ START_TEST(status) test_create(); test_height(); test_status_ownerdraw(); + test_gettext(); }