[PATCH 1/3] Handle NULL item text case to avoid crash
Nikolay Sivov
bunglehead at gmail.com
Tue Oct 13 11:59:39 CDT 2009
---
dlls/comctl32/comboex.c | 12 ++++++++++++
dlls/comctl32/tests/comboex.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/dlls/comctl32/comboex.c b/dlls/comctl32/comboex.c
index d67b918..4de471d 100644
--- a/dlls/comctl32/comboex.c
+++ b/dlls/comctl32/comboex.c
@@ -510,6 +510,17 @@ static UINT COMBOEX_GetListboxText(const COMBOEX_INFO *infoPtr, INT_PTR n, LPWST
return 0;
str = COMBOEX_GetText(infoPtr, item);
+ if (!str)
+ {
+ if (buf)
+ {
+ if (infoPtr->unicode)
+ buf[0] = 0;
+ else
+ *((LPSTR)buf) = 0;
+ }
+ return 0;
+ }
if (infoPtr->unicode)
{
@@ -985,6 +996,7 @@ static LRESULT COMBOEX_Create (HWND hwnd, CREATESTRUCTA const *cs)
infoPtr->selected = -1;
infoPtr->unicode = IsWindowUnicode (hwnd);
+//ERR("%d\n", infoPtr->unicode);
infoPtr->hwndNotify = cs->hwndParent;
i = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
diff --git a/dlls/comctl32/tests/comboex.c b/dlls/comctl32/tests/comboex.c
index 1e74192..8a1e253 100644
--- a/dlls/comctl32/tests/comboex.c
+++ b/dlls/comctl32/tests/comboex.c
@@ -288,6 +288,41 @@ static void test_WM_LBUTTONDOWN(void)
DestroyWindow(hComboEx);
}
+static void test_CB_GETLBTEXT(void)
+{
+ HWND hCombo;
+ CHAR buff[1];
+ COMBOBOXEXITEMA item;
+ LRESULT ret;
+
+ hCombo = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
+
+ /* set text to null */
+ addItem(hCombo, 0, NULL);
+
+ buff[0] = 'a';
+ item.mask = CBEIF_TEXT;
+ item.iItem = 0;
+ item.pszText = buff;
+ item.cchTextMax = 1;
+ ret = SendMessage(hCombo, CBEM_GETITEMA, 0, (LPARAM)&item);
+ ok(ret != 0, "CBEM_GETITEM failed\n");
+ ok(buff[0] == 0, "\n");
+
+ ret = SendMessage(hCombo, CB_GETLBTEXTLEN, 0, 0);
+ ok(ret == 0, "Expected zero length\n");
+
+ ret = SendMessage(hCombo, CB_GETLBTEXTLEN, 0, 0);
+ ok(ret == 0, "Expected zero length\n");
+
+ buff[0] = 'a';
+ ret = SendMessage(hCombo, CB_GETLBTEXT, 0, (LPARAM)buff);
+ ok(ret == 0, "Expected zero length\n");
+ ok(buff[0] == 0, "Expected null terminator as a string, got %s\n", buff);
+
+ DestroyWindow(hCombo);
+}
+
static LRESULT CALLBACK ComboExTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
@@ -362,6 +397,7 @@ START_TEST(comboex)
test_comboboxex();
test_WM_LBUTTONDOWN();
+ test_CB_GETLBTEXT();
cleanup();
}
--
1.5.6.5
--=-zYsQ0CQPIQcMXShgyj/0--
More information about the wine-patches
mailing list